Terry Reedy wrote: > "Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >>> 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 | [EMAIL PROTECTED] | Brisbane, Australia --------------------------------------------------------------- http://www.boredomandlaziness.org _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com