如何在不执行的情况下检查 Python 脚本的语法? [英] How can I check the syntax of Python script without executing it?
本文介绍了如何在不执行的情况下检查 Python 脚本的语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我曾经使用 perl -c programfile
检查 Perl 程序的语法,然后不执行就退出.是否有对 Python 脚本执行此操作的等效方法?
I used to use perl -c programfile
to check the syntax of a Perl program and then exit without executing it. Is there an equivalent way to do this for a Python script?
推荐答案
可以通过编译来检查语法:
You can check the syntax by compiling it:
python -m py_compile script.py
这篇关于如何在不执行的情况下检查 Python 脚本的语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文