> In Perl, you can perl -c somehardtoreadperlprogram.pl that will just
> check the syntax. The above problem would have been caught in Perl since
> I always use strict. Is there a command line option in Python to do a
> Pychecker-like syntax check?

Hi Mike,

Unfortunately, no, because there are some really funky things that one can
do in Python that you can't do easily in Perl.  For example, Python allows
one to inject new names into existing modules:

######
>>> import StringIO
>>> StringIO.foo = 'bar'
######


Python uses a "late binding" module for name lookup, where the variable
lookup happens as late as it can.

There are some places where something like this has been useful.  For
example, it's sometimes been useful to replace the standard file objects
systemwide by doing this:

######
>>> import sys
>>> import StringIO
>>> import sys
>>> sys.stderr = StringIO.StringIO()
>>> blah
>>> print sys.stderr.getvalue()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: name 'blah' is not defined
######

which is sorta cool.  But it also makes it possible to completely break
encapsulation --- Parnas would not be happy.


Python's late binding does make typos a bit maddening, since those become
runtime errors rather than compile-time ones.  PyChecker uses a model
that's a bit more strict than Python's, and that's how it catches things
like typos.


> I see a -t to check the tabs, but nothing to tell it to check the syntax
> but don't run it. If not, should Pychecker be part of the standard
> distribution?  Am I missing something?

You may want to talk with the PyChecker developers to see what their
future plans are.

    http://pychecker.sourceforge.net/


Best of wishes!

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to