possible bug of parser.suite

Alex Martelli aleax at aleax.it
Fri Jul 5 12:53:53 EDT 2002


Fan Guanping wrote:

> parser.suite seems broken at least in Python '2.2.1 (#34, Apr 15 2002,
> 09:51:39)
> [MSC 32 bit (Intel)]'. Is this a bug,or I use it incorrectly?
> 
>>>> parser.suite('class Abc:pass')
> <parser.st object at 0x007B5F48>
>>>> parser.suite('class Abc:\n    def hello(self):\n            pass')
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> parser.ParserError: could not parse string

I think you just need a trailing \n in the second case -- as you've 
indented, you must also dedent, or else your suite isn't complete.

Note that in the first case there was no indent, so no need for a
dedent and therefore no need for trailing \n either (though it would
not hurt).


Alex




More information about the Python-list mailing list