Re: [Pyparsing] Access nested ParseResults
Brought to you by:
ptmcg
From: <pt...@au...> - 2012-08-16 20:43:50
|
To keep the different names of each pair separate, you'll need to enclose pp1 in a Group: pp1=py.Group(py.Word(py.alphanums)("name") + py.Word(py.nums)("number")) Now when you parse your string, r2.list will contain a list of paired name-values: r2=pp2.parseString("BAR 10, ZAP 20") for pair in r2.list: print pair.name, pair.number To get at an individual element, just using sliced indexing, just like it was a normal list: print r2.list[0].name -- Paul |