super, decorators and gettattribute
steve at REMOVE-THIS-cybersource.com.au
Sun Jan 13 00:56:21 CET 2008
On Sat, 12 Jan 2008 15:47:05 -0500, Mike Meyer wrote:
> There's an apparently common bug here: you don't want to pass super
> self.__class__, but the class that the method is bound to.
Given an instance method, is it possible to easily determine what class
it is defined in?
I thought the im_class attribute might do it, but it apparently just
points to self.__class__.
>>> class Foo(object):
... def foo(self):
>>> class Bar(Foo):
... def bar(self):
>>> Bar().bar.im_class # expecting Bar
>>> Bar().foo.im_class # hoping for Foo
More information about the Python-list