Python switch for syntax checking
Scott David Daniels
Scott.Daniels at Acm.Org
Fri Nov 19 18:55:01 EST 2004
Jeff Duffy originally wrote:
> I've been wondering why python itself doesn't provide a switch to
> check a file for valid syntax....
> Jeff Shannon wrote:
> Bengt Richter wrote:
>> On Fri, 19 Nov 2004 12:08:00 -0800, Scott David Daniels
>> <Scott.Daniels at Acm.Org> wrote:
>>> 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,
>
> I believe that Scott is referring to the difference between a file run
> from the commandline, in which __name__ is set to "__main__", and a file
> that's imported as a module, in which __name__ is set to the name of the
> module, which is normally the filename minus the .py[c|o|d] extension.
>
I do mean something like that. Essentially, I mean "if the file is
meant to be imported, rather than run."
> Of course, this would also imply that Scott is presuming that one is
> following the good programming practice of not putting any significant
> code (other than function, class, and global variable definitions) at
> module level, except where protected by an 'if __name__ == "__main__":'
> statement. That *is* good practice, and most people do it, but it's not
> required so perhaps not a safe presumption...
Remember, I am explaining why we normally don't have a syntax-check-only
option, and my thesis is that there is no perceived need on the part of
the core implementers.
--Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-list
mailing list