compilation – How can I check the syntax of Python script without executing it?

compilation – How can I check the syntax of Python script without executing it?

You can check the syntax by compiling it:

python -m py_compile script.py

You can use these tools:

compilation – How can I check the syntax of Python script without executing it?

import sys
filename = sys.argv[1]
source = open(filename, r).read() + n
compile(source, filename, exec)

Save this as checker.py and run python checker.py yourpyfile.py.

Leave a Reply

Your email address will not be published. Required fields are marked *