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
[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)
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']
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:,
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
--
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
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:,
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:
[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
--
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
('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
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'
12 matches
Mail list logo