method = Klass.othermethod considered PITA

John J. Lee jjl at
Sun Jun 5 00:43:39 CEST 2005

It seems nice to do this

class Klass:

    def _makeLoudNoise(self, *blah):

    woof = _makeLoudNoise

One probably wants the above to work as if you'd instead defined woof
in the more verbose form as follows:

    def woof(self, *blah): return self._makeLoudNoise(self, *blah)

It doesn't, though.  Two problems:

1. In derived classes, inheritance doesn't work right:

>>> class A:
...  def foo(s):print 'foo'
...  bar = foo
>>> a = A()
>>> class B(A):
...  def foo(s):print 'moo'
>>> b = B()

2. At least in 2.3 (and 2.4, AFAIK), you can't pickle classes that do


More information about the Python-list mailing list