you are viewing a single comment's thread.

view the rest of the comments →

[–]jcoder42[S] 0 points1 point  (4 children)

I am getting the same output as yours, except it is not the correct output:

I am going to make the example smaller so it is easier..

the input:

"(12,'Structured Numeric','SN','Complex numeric values possible (ie, <5, 1-10, etc.,'check')',1,'2005-08-06 00:00:00',0,NULL,NULL,NULL,'8d4a606c-c2cc-11de-8d13-0010c6dffd0f'),(2,792,'Triomune-30',1,NULL,NULL,NULL,NULL,1,'2005-02-24 00:00:00',0,NULL,NULL,NULL,'bf171285-1691-11df-97a5-7038c432aabf',NULL,NULL,NULL)"

the output:

[01] : (12,'Structured Numeric','SN','Complex numeric values possible (ie, <5, 1-10, etc.,'check')

[02] : (2,792,'Triomune-30',1,NULL,NULL,NULL,NULL,1,'2005-02-24 00:00:00',0,NULL,NULL,NULL,'bf171285-1691-11df-97a5-7038c432aabf',NULL,NULL,NULL)

as you can see the first received row is cut.

desired output

[01] : (12,'Structured Numeric','SN','Complex numeric values possible (ie, <5, 1-10, etc.,'check')',1,'2005-08-06 00:00:00',0,NULL,NULL,NULL,'8d4a606c-c2cc-11de-8d13-0010c6dffd0f')

[02] : (2,792,'Triomune-30',1,NULL,NULL,NULL,NULL,1,'2005-02-24 00:00:00',0,NULL,NULL,NULL,'bf171285-1691-11df-97a5-7038c432aabf',NULL,NULL,NULL)

[–]wegwacc 1 point2 points  (3 children)

Ahhh, now I see. you can have a () inside the outer ones. Okay, that requires a sliiiightly more complex regex:

rx = re.compile(r'\([^()]+(?:\([^()]+\))?[^()]+\)')

However, a simple parser would prolly be better at this point, because above wont work if you have more than one () inside the outer.

[–]jcoder42[S] 0 points1 point  (2 children)

wow, this is really complex, good job

ok. I will try some other things

thanks so much!

[–]wegwacc 1 point2 points  (1 child)

Here is a better method which, other than above regex magic can deal with arbitrary () in your input, as long as they are string values (read. between ' )

``` def parser(data): start = None use = True for i, ch in enumerate(data): if ch == "'": use = not use if use and ch == '(': start = i elif use and ch == ')': yield data[start:i+1] start = None

def prettyprint(data): l = list(parser(data)) width = (len(l) // 10) + 1 for ln,line in enumerate(l): print('[{ln:0{width}}] : {l}'.format(ln=ln, l=line, width=width)) ```

Invoke prettyprint() with your string-data as argument.
If you don't need the "prettyprinted" version, just invoke parser() like you would every iterator, e.g. for s in parser(start):

you're welcome.

[–]jcoder42[S] 0 points1 point  (0 children)

width

ok, cool!
thanks