compiler module bug?

Brian Blais bblais at bryant.edu
Sun Oct 21 13:33:00 EDT 2007


On Oct 21, 2007, at Oct 21:1:15 PM, Gabriel Genellina wrote:

> En Sun, 21 Oct 2007 13:36:46 -0300, Brian Blais <bblais at bryant.edu>
> escribi�:
>
>> I am experiencing a problem with the compiler module.  Is this a bug,
>> or am I doing something wrong?
>
> I think it's a well-known fact...
>
>> it seems like a comment at the end breaks the parse command, but not
>> parseFile.  Is this reproducible by others?
>
> The comment itself is not a problem; but the last line in the  
> source must
> end in a newline.
> See the py_compile/compileall modules as an example.


I didn't see anything in that module which mentions this issue  
(perhaps I missed it).  however, if the documentation states:

parseFile(
path)
Return an abstract syntax tree for the Python source code in the file  
specified by path. It is equivalent to parse(open(path).read()).

then, even if it is known problem, the docs are wrong.  the two  
(parseFile(path) and parse(open(path).read())) are *not* the same:  
one can handle a file which doesn't end in a newline, another one  
can't handle the same file.

Can one hack it like:

     filestr=open(filename).read()
     filestr+="\n"

before going to parse, or will that give problems?

		thanks,

			bb


-- 
Brian Blais
bblais at bryant.edu
http://web.bryant.edu/~bblais



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20071021/3d1fceec/attachment.html>


More information about the Python-list mailing list