开发者

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

开发者 https://www.devze.com 2022-12-08 01:09 出处:网络
Perl has the -c switch to compile the code without running it.This i开发者_运维技巧s convenient for debugging compile errors in Perl.

Perl has the -c switch to compile the code without running it. This i开发者_运维技巧s convenient for debugging compile errors in Perl.

Does Python have a similar switch?


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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号