Beginner question: Converting Single-Element tuples to list
Paul McGuire
ptmcg at austin.rr.com
Mon Jun 27 12:15:23 EDT 2005
Modified version of test program, to handle empty strings -> empty
lists.
import pyparsing as pp
import sys
def test(s):
results = pp.ZeroOrMore( pp.Word(pp.alphas) ).parseString( s )
print repr(s),"->",list(results)
print "Python version:", sys.version
print "pyparsing version:", pp.__version__
test("abc def")
test("abc")
test("")
Prints:
Python version: 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit
(Intel)]
pyparsing version: 1.3.1
'abc def' -> ['abc', 'def']
'abc' -> ['abc']
'' -> []
More information about the Python-list
mailing list