Python switch for syntax checking

Bengt Richter bokr at oz.net
Fri Nov 19 17:07:32 EST 2004


On Fri, 19 Nov 2004 12:08:00 -0800, Scott David Daniels <Scott.Daniels at Acm.Org> wrote:

>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
??? What does "not a main program mean"? I'm not sure what you mean, e.g.,

 [14:00] C:\pywk\clp>python notmain.py
 notmain.py executing

 [14:00] C:\pywk\clp>python
 Python 2.3.2 (#49, Oct  2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] on win32
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import notmain
 notmain.py executing
 >>> ^Z


 [14:00] C:\pywk\clp>py24
 Python 2.4b1 (#56, Nov  3 2004, 01:47:27)
 [GCC 3.2.3 (mingw special 20030504-1)] on win32
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import notmain
 notmain.py executing

Oops, forgot to show you what notmain.py was:

 >>> print '%s\n%s%s' % ('-'*40, open('notmain.py').read(), '-'*40)
 ----------------------------------------
 print 'notmain.py executing'

 ----------------------------------------

>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
>

Regards,
Bengt Richter



More information about the Python-list mailing list