On 27/05/13 07:40, Jim Mooney wrote:

Good to know that compile doesn't check syntax, since I erroneously
thought it did.

compile does check syntax.


py> compile("23 = 43", "", "exec")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "", line 1
SyntaxError: can't assign to literal


The compile built-in function does the same as the Python compiler that 
compiles your code before you run it. It has three modes:

- "exec", which operates in the same way that Python compiles a module;

- "single", which operates in the same way that Python compiles a single 
statement in the interactive interpreter; and

- "eval", which tells Python that the code must be a single expression and not 
a statement or a block of code.



--
Steven
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to