Terry Reedy wrote: > "Fredrik Lundh" <fredrik at pythonware.com> wrote in message > news:dveini$ntv$1 at sea.gmane.org... >>> http://sourceforge.net/tracker/index.php?func=detail&aid=1184112&group_id=5470&atid=105470 >> "When compiling multi-line statements, two caveats apply: line >> endings must be represented by a single newline character ('\n'), >> and the input must be terminated by at least one newline character." > > Relevant part of quote added to bug report. One quirk though, is that omitting the newline actually works for some other statements (e.g. exec "if 1:\n print 'Hello world!'" works just fine) However, I don't think the quote is as relevant as one might think, because in the code that fails the multi-line statement is not only terminated by a newline, it's actually followed by a blank line as well. The line missing the newline is only a single-line statement (specifically, a line with only a comment). Compare: Py> exec """ ... if 1: ... print 'This works!' ... ... pass # Do nothing at all""" This works! With: Py> exec """ ... if 1: ... print 'This breaks!' ... ... # Do nothing at all""" Traceback (most recent call last): File "<stdin>", line 1, in ? File "<string>", line 5 # Do nothing at all ^ SyntaxError: invalid syntax There's an easy workaround (adding the missing newline), but I think there's definitely something going wrong in the tokenizer. Cheers, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia --------------------------------------------------------------- http://www.boredomandlaziness.org
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4