What's wrong with that comment?

Ludwig Miniatur Ludwig at armand-miniatur.de
Tue May 20 14:52:30 EDT 2008


Hi, I ran into a funny thing when I played with the python parser, to
build a python call graph for learning...

When I have a (special) python program, that runs without any error it
gives an error, when I try to parse it parser.suite. The error is,
when my program has a comment on the last line after an indented
block. Note that there no newline behind "# comment". With a newline
everything is fine.

For example:
#!/usr/bin/env python

from parser import suite, ast2list
fh = file(__file__)
s = fh.read()
fh.close()
ast = suite(s)

while False:
  print "hello world"
# comment

Looks like a little bug in parser; but what I don't understand is that
I thought parser was build with the current syntax of python.

So, why can python run the script (an it can if you comment out the
line "ast = suite(s)") but parser can't?

Looking forward for answers...

Ludwig



More information about the Python-list mailing list