I am developing a tool which has to accept a file as an input, check syntax errors, compile it and do something after that.
For example, I have a file run.py:
a=5
b=c
print b
This should clearly show a syntax error while compiling because 'c' is not defined
I tried to use
try:
py_compile.compile("source_program/run.py", doraise=True)
print "Compiled"
except:
print "Error while compiling"
I get the output "Compiled" instead of "Error while compiling"
If I modify the run.py file as:
a=5
b=c/ #Instead of b=c
print b
Then I get the output "Error while compiling"
What don't I get an error message in the first case?
b = cwithcnot defined is not a SyntaxError but a NameError