Re: [Pyparsing] CSVs with trailing comma
Brought to you by:
ptmcg
From: Paul M. <pa...@al...> - 2007-09-03 22:56:24
|
Nathan, Not sure what you mean by "unfortunately doesnt work." I tried your example pretty much verbatim, and I got this: >>> from pyparsing import * >>> data = "a,b," >>> foo = delimitedList(Word(alphanums)) >>> (foo+stringEnd).parseString(data) Traceback (most recent call last): <snip> pyparsing.ParseException: Expected stringEnd (at char 3), (line:1, col:4) >>> (foo+Optional(",").suppress() + stringEnd).parseString(data) (['a', 'b'], {}) There is also the pyparsing built-in, commaSeparatedList: >>> commaSeparatedList.parseString(data) (['a', 'b', ''], {}) Note that it treats the trailing comma as a delimiter with a blank item at the end. -- Paul -----Original Message----- From: pyp...@li... [mailto:pyp...@li...] On Behalf Of Nathan Harmston Sent: Monday, September 03, 2007 4:47 PM To: pyp...@li... Subject: [Pyparsing] CSVs with trailing comma Hi, If I have a comma-separated list a,b, # notice the trailing comma how can I specify a grammar to ignore the trailing comma..... foo = delimitedList( Word(alphanums, delim=",") The only I could think off was foo + Optional(",").suppress(), which unfortunately doesnt work. Is there a way to this in pyparsing? Many Thanks in advance, Nathan ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ Pyparsing-users mailing list Pyp...@li... https://lists.sourceforge.net/lists/listinfo/pyparsing-users |