How to get a reference of the 'owner' class to which a method belongs in Python 3.X?

Chris Rebert clp2 at rebertia.com
Sat Mar 17 06:51:05 CET 2012


On Fri, Mar 16, 2012 at 10:30 PM, Cosmia Luna <cosmius at gmail.com> wrote:
> I'm porting my existing work to Python 3.X, but...
>
> class Foo:
>    def bar(self):
>        pass
>
> mthd = Foo.bar
>
> assert mthd.im_class is Foo # this does not work in py3k
>
> So, how can I get a reference to Foo? This is important when writing
> decorators,

Could you give an example of such a decorator?

Cheers,
Chris



More information about the Python-list mailing list