可能重复:
How can I check the syntax of Python script without executing it?
如何在不运行Python脚本的情况下编译它?我只想检查脚本中的语法错误。我希望有一个简单的命令行开关,但我在python --help
中没有看到任何东西。我想要一个关于Python 2和Python 3的答案。
发布于 2010-12-27 16:23:06
py_compile — Compile Python source files
import py_compile
py_compile.compile('my_script.py')
发布于 2011-12-09 04:56:14
python -m py_compile script.py
发布于 2010-12-27 16:28:02
您可以使用pylint来查找语法错误以及更细微的错误,比如在一些很少使用的条件分支中访问未定义的变量。
https://stackoverflow.com/questions/4537411
复制相似问题