Python switch for syntax checking

Scott David Daniels Scott.Daniels at Acm.Org
Fri Nov 19 15:08:00 EST 2004


Jeff Duffy wrote:
>  I've been wondering why python itself doesn't provide a switch to check 
> a file for valid syntax. I know that you can currently call
> python -c "import py_compile; py_compile.compile(r'MyApp.py')"
> ...
I suspect the reason is threefold.

First, "python MyApp.py" does a syntax check anyway.  If MyApp is
not a main program, all you get is the syntax check.  As for main
programs, larger applications are often split into smaller files.
I seldom have large main program files to check.

Second, lots of extreme programmer (XP) practitioners hang out here,
and even more who have adopted at leasrt some of the XP techniques.
Those people tend to run unit tests rather than syntax checks.

Third, pychecker provides better analysis if you want static analysis.

I pretty much try to go the unit test way myself.  While I would
suggest you try it out, the three reasons above are meant to explain
why nobody has put effort into a syntax check switch.

--Scott David Daniels
Scott.Daniels at Acm.Org




More information about the Python-list mailing list