This isn't a regex solution, but uses pyparsing instead. Pyparsing
helps you construct recursive-descent parsers, and maintains a code
structure that is easy to compose, read, understand, maintain, and
remember what you did 6-months after you wrote it in the first place.
Download pyparsing at
Scott wrote:
I have a file with lines in the following format.
pie=apple,quantity=1,cooked=yes,ingredients='sugar and cinnamon'
Pie=peach,quantity=2,ingredients='peaches,powdered sugar'
Pie=cherry,quantity=3,cooked=no,price=5,ingredients='cherries and sugar'
I would like to pull out some
Paul McGuire wrote:
This isn't a regex solution, but uses pyparsing instead. Pyparsing
helps you construct recursive-descent parsers, and maintains a code
structure that is easy to compose, read, understand, maintain, and
remember what you did 6-months after you wrote it in the first place.
Catalina Scott A Contr AFCA/EVEO schrieb:
I have a file with lines in the following format.
pie=apple,quantity=1,cooked=yes,ingredients='sugar and cinnamon'
Pie=peach,quantity=2,ingredients='peaches,powdered sugar'
Pie=cherry,quantity=3,cooked=no,price=5,ingredients='cherries and sugar'
I
Christopher Subich schrieb:
Paul McGuire wrote:
[...]
For the example listed, pyparsing is even overkill; the OP should
probably use the csv module.
But the OP wants to parse lines with key=value pairs, not simply lines
with comma separated values. Using the csv module will just separate
Fredrik Lundh wrote:
Scott wrote:
I have a file with lines in the following format.
pie=apple,quantity=1,cooked=yes,ingredients='sugar and cinnamon'
Pie=peach,quantity=2,ingredients='peaches,powdered sugar'
Pie=cherry,quantity=3,cooked=no,price=5,ingredients='cherries and sugar'
I
Dennis Benzinger wrote:
Christopher Subich schrieb:
Paul McGuire wrote:
[...]
For the example listed, pyparsing is even overkill; the OP should
probably use the csv module.
But the OP wants to parse lines with key=value pairs, not simply lines
with comma separated values. Using the csv
Catalina Scott A Contr AFCA/EVEO wrote:
I have a file with lines in the following format.
pie=apple,quantity=1,cooked=yes,ingredients='sugar and cinnamon'
Pie=peach,quantity=2,ingredients='peaches,powdered sugar'
Pie=cherry,quantity=3,cooked=no,price=5,ingredients='cherries and sugar'
I