pychecker question

Erik Max Francis max at alcyone.com
Mon Feb 3 19:49:47 EST 2003


Markus Jais wrote:

> class MyClass:
> 
>         def __init__(self):
>                 self.x = ""
>                 #return 42
> 
>         def func(self, arg1):
>                 print "%d |" % (arg1)
> 
>         def func(self, str):
>                 print str + "|"
	...
> pychecher correctly reports that there is a problem with the "func"
> method
> because it is redefined.

And right it is; MyClass has two methods named func.  Python does not
support function overloading, so the second definition completely
overrides the first as if it never existed.  (How could it have function
overloading based on type, when there are no type declarations?)

You seem to just want to print the string value of an object followed by
a slash (though it's not clear whether you want an intervening space),
so just write:

	def func(self, thing):
	    print "%s |" % thing

The %s specifier does an automatic call to str to its argument, so this
will work with any object that is convertible to a string (either
natively or because it defines a __str__ method).

> is there a list with all the errors pychecker reports that are also
> reportet 
> by the Python interpreter ???

PyChecker is specifically intended to try to catch probable errors that
are _not_ syntactical Python errors.  It tries to look at your code,
understanding that it's legal, and analyze it for possible mistakes.  If
the code contains actual Python errors, then PyChecker won't run (at
least the last time I checked, which was long ago; I"m not in the habit
of running PyChecker on Python scripts that won't even pass a syntax
check).

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ In wildness is the preservation of the world.
\__/ Henry David Thoreau
    Alcyone Systems / http://www.alcyone.com/
 Alcyone Systems, San Jose, California.




More information about the Python-list mailing list