Parser needed.
Skybuck Flying
skybuck2000 at hotmail.com
Mon Jun 1 21:01:18 EDT 2015
This can help with parsing the C like bracketted data:
http://stackoverflow.com/questions/1651487/python-parsing-bracketed-blocks
algo:
"
For each string in the array:
Find the first '{'. If there is none, leave that string alone.
Init a counter to 0.
For each character in the string:
If you see a '{', increment the counter.
If you see a '}', decrement the counter.
If the counter reaches 0, break.
Here, if your counter is not 0, you have invalid input (unbalanced
brackets)
If it is, then take the string from the first '{' up to the '}' that put
the
counter at 0, and that is a new element in your array."Not sure what
this is, but more points: Or this pyparsing version:>>> from pyparsing
import nestedExpr
>>> txt = "{ { a } { b } { { { c } } } }"
>>>
>>> nestedExpr('{','}').parseString(txt).asList()
[[['a'], ['b'], [[['c']]]]]
>>> Not sure if I want a data structure like that... not sure what data
>>> structure it is anyway... seems to be a list in a list in a list...
>>> hmm.... Bye, Skybuck.
More information about the Python-list
mailing list