compile() error

Steven D'Aprano steve-REMOVE-THIS at cybersource.com.au
Wed May 19 20:52:06 EDT 2010


On Wed, 19 May 2010 22:31:31 +0000, Benjamin Peterson wrote:

> Iuri <iurisilvio <at> gmail.com> writes:
>> Any ideas about what is happening?
> 
> Until Python 2.7/3.2, compile() does't like sources which don't end in a
> newline.


Are you sure about that?


>>> x = compile("print __import__('sys').version, 'see ma, no newline'", 
"", "single")
>>> exec x
2.5 (r25:51908, Nov  6 2007, 16:54:01)
[GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] see ma, no newline


The original post isn't showing up for me, so I don't know the full 
context, but it seems to me that compile can deal with the lack of 
newline.


>>> x = compile("""import sys
... print sys.version
... print 'see ma, still no final newline!'""", "", "exec")
>>> exec x
2.5 (r25:51908, Nov  6 2007, 16:54:01)
[GCC 4.1.2 20070925 (Red Hat 4.1.2-27)]
see ma, still no final newline!




-- 
Steven



More information about the Python-list mailing list