Re: Beginner question: Converting Single-Element tuples to list

2005-06-29 Thread Paul McGuire
Steve - Good catch - in v1.3, I added some Unicode support for pyparsing, although I have not gotten much feedback that anyone is using it, or how well it works. So it is preferable to test against basestring instead of str. -- Paul -- http://mail.python.org/mailman/listinfo/python-list

Re: Beginner question: Converting Single-Element tuples to list

2005-06-27 Thread Reinhold Birkenfeld
[EMAIL PROTECTED] wrote: Hi, Thanks for your reply! A new thing learned Allow me to follow that up with another question: Let's say I have a result from a module called pyparsing: Results1 = ['abc', 'def'] Results2 = ['abc'] They are of the ParseResults type: type(Results1)

Re: Beginner question: Converting Single-Element tuples to list

2005-06-27 Thread John Roth
Reinhold Birkenfeld [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, Thanks for your reply! A new thing learned Allow me to follow that up with another question: Let's say I have a result from a module called pyparsing: Results1 = ['abc', 'def']

Re: Beginner question: Converting Single-Element tuples to list

2005-06-27 Thread Paul McGuire
David - I'm not getting the same results. Run this test program: --- import pyparsing as pp import sys def test(s): results = pp.OneOrMore( pp.Word(pp.alphas) ).parseString( s ) print repr(s),-,list(results) print Python version:, sys.version print pyparsing version:,

Re: Beginner question: Converting Single-Element tuples to list

2005-06-27 Thread Paul McGuire
John - I just modified my test program BNF to use ZeroOrMore instead of OneOrMore, and parsed an empty string. Calling list() on the returned results gives an empty list. What version of pyparsing are you seeing this None/object/list behavior? -- Paul --

Re: Beginner question: Converting Single-Element tuples to list

2005-06-27 Thread Jeff Epler
On Mon, Jun 27, 2005 at 08:21:41AM -0600, John Roth wrote: Unfortunately, I've seen that behavior a number of times: no output is None, one output is the object, more than one is a list of objects. That forces you to have checks for None and list types all over the place. maybe you can at

Re: Beginner question: Converting Single-Element tuples to list

2005-06-27 Thread Paul McGuire
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:,

Re: Beginner question: Converting Single-Element tuples to list

2005-06-27 Thread vdavidster
Hi Paul and everyone else, I ran the script and here's what I got: Python version: 2.4.1 (#2, Mar 31 2005, 00:05:10) [GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] pyparsing version: 1.3 'abc def' - ['abc', 'def'] 'abc' - ['abc'] It seems to work fine. I figured out what my problem was:

Re: Beginner question: Converting Single-Element tuples to list

2005-06-27 Thread Steven Bethard
[EMAIL PROTECTED] wrote: if type(input) == str: You might consider writing this as: if isinstance(input, basestring): I don't know if pyparsing ever produces unicode objects, but in case it does (or it starts to in the future), isinstance is a better call here. STeVe --

Beginner question: Converting Single-Element tuples to list

2005-06-26 Thread vdavidster
Hello everyone, I want to convert a tuple to a list, and I expected this behavior: list(('abc','def')) - ['abc','def'] list(('abc')) - ['abc'] But Python gave me this behavior: list(('abc','def')) - ['abc','def'] list(('abc')) - ['a','b','c'] How do I do get Python to work like the in former

Re: Beginner question: Converting Single-Element tuples to list

2005-06-26 Thread Paul McGuire
('abc') is not a tuple - this is an unfortunate result of using ()'s as expression grouping *and* as tuple delimiters. To make ('abc') a tuple, you must add an extra comma, as ('abc',). list( ('abc',) ) ['abc'] -- Paul -- http://mail.python.org/mailman/listinfo/python-list

Re: Beginner question: Converting Single-Element tuples to list

2005-06-26 Thread vdavidster
Hi, Thanks for your reply! A new thing learned Allow me to follow that up with another question: Let's say I have a result from a module called pyparsing: Results1 = ['abc', 'def'] Results2 = ['abc'] They are of the ParseResults type: type(Results1) class 'pyparsing.ParseResults'