If you want to check the syntax of Python script without executing it then you can use the following command:
python -m py_compile script.py
Another thing you can do is by writing the following code and after writing the code you will save the code as checker.py and use the python checker.py yourpyfile.py. the command to run the code without executing.
import sys
filename = sys.argv[1]
source = open(filename, 'r').read() + '\n'
compile(source, filename, 'exec')