[Python] syntax check for python?
Bob Miller
kbob at jogger-egg.com
Fri Feb 2 09:31:17 PST 2007
Rob Hudson wrote:
> Is there a way to syntax check a .py file without actually running it?
>
> I know Perl has perl -c.
> I know PHP has php -l.
>
> What does Python have?
$ python -c 'import myfile'
Of course, if myfile contains executable statements, as opposed to
class and function definitions, those statements will be executed.
That's why you wrapped your executable statements in one of these.
if __name__ == '__main__':
# ...
There's probably a safer option using the parser module.
--
Bob Miller K<bob>
kbob at jogger-egg.com
More information about the Python
mailing list