Steven, it works fine to some cases. I have problem only when last line is a comment and before it I have an indentation. It is a specific case, and it is not a common case.
>>> compile("for i in [1,2,3]:\n pass\n#end", "test_file.py", "exec") What I understanded about Benjamin's answer is compile() without a new line at the end has an indetermined behaviour, so in some cases it works. Iuri de Silvio On Wed, May 19, 2010 at 9:52 PM, Steven D'Aprano < steve-remove-t...@cybersource.com.au> wrote: > 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 > -- > http://mail.python.org/mailman/listinfo/python-list >
-- http://mail.python.org/mailman/listinfo/python-list