Is it possible to seperate Python's Syntax checker from the Interpreter?

Carsten Gaebler news at snakefarm.org
Tue Dec 17 11:51:41 EST 2002


Jason Keith Ergle wrote:
> I am developing a simple Python IDE for one of our apps.  I need to allow the users a simple way of checking the correctness of the syntax of their Python code.  I wanted to use the Python interpreter, but I cannot allow the user to execute their code at this point.  Is their a way I can force the interpreter to just do its syntax check, and then exit without attempting to execute the code?  Any hel would be appreciated, thanks.
> 

If you really only care about sytax errors, you can use the py_compile 
module. I wrote myself this little script for checking the syntax of my 
scripts:


#! /usr/bin/python -tt

import py_compile, sys, os

file = sys.argv[1]
py_compile.compile(file)

# remove the compiled code
if os.path.isfile(file + "c"):
	os.remove(file + "c")



cg.




More information about the Python-list mailing list