Nathan Fellman
Nathan Fellman

Reputation: 127468

Does Python have a "compile only" switch like Perl's -c?

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?

Upvotes: 18

Views: 6874

Answers (3)

nosklo
nosklo

Reputation: 222862

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

Upvotes: 9

Warren Young
Warren Young

Reputation: 42343

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.

Upvotes: 0

Eli Courtwright
Eli Courtwright

Reputation: 192961

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.

Upvotes: 23

Related Questions