views:

137

answers:

3

Perl has the -c switch to compile the code without running it. This is convenient for debugging compile errors in Perl.

Does Python have a similar switch?

+3  A: 

You can say

python -m py_compile script_to_check.py

However, this will have the side effect of creating a compiled script_to_check.pyc file in the same directory as your script. This feature is designed to speed up later uses of a module rather than to make sure that your syntax is correct, though you could certainly use it for that.

Eli Courtwright
A: 

Through 2.6, there's the compiler package. That page doesn't say if there is a replacement in 3.0, or if you just can't do that any more.

Warren Young
there is a built-in `compile` function http://docs.python.org/3.1/library/functions.html#compile
SilentGhost
+3  A: 

Even better is to run pyflakes, pychecker or maybe pylint at the code. They catch some common errors that compiling won't.

nosklo