What's wrong with that comment?

Ludwig Miniatur Ludwig at armand-miniatur.de
Wed May 21 01:34:21 EDT 2008


On 21 Mai, 00:12, "Gabriel Genellina" <gagsl-... at yahoo.com.ar> wrote:
> En Tue, 20 May 2008 16:22:10 -0300, Joe P. Cool
> <joe.p.c... at googlemail.com> escribió:
>
>
>
> > Ludwig Miniatur wrote:
> >> 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.
>
> > I didn't read the grammar but I assume that Python grammar requires a
> > comment to have the form #.*<end-of-line>.
>
> >> So, why can python run the script (an it can if you comment out the
> >> line "ast = suite(s)") but parser can't?
>
> > The interpreter probably appends a newline after the input stream as a
> > friendly service :)
>
> Something like that. The last line of source *must* end in a newline (be
> it a comment or not); this is a known limitation. See py_compile.py for an
> example.
>
> --
> Gabriel Genellina

Uoh, you never stop learning...
Thanks for the explanation. I thought something like that, but it made
me some headaches.

Lutz



More information about the Python-list mailing list