importing a method

Martin Miller ggrp1.20.martineau at
Thu Dec 1 01:34:30 CET 2005

You're not missing anything -- it's my own [mis-]understanding that
descriptors would only work with new-style classes, not the old-style
ones used in the OP's example.

However your example certainly proves that is not the case, even if you
go one step further and call the bound method/function:
>>> o.z()
<__main__.old instance at 0x009D5F30>

So I stand corrected -- thank you.


Alex Martelli wrote:
> Martin Miller <ggrp1.20.martineau at> wrote:
> > I'd like to point out to the OP that using a function's __get__ method
> > this way only works with new-style classes and their instances...not
> > with the example in the shown in original post.
> Uh, why not?
> >>> class old: pass
> ...
> >>> def f(self): print self
> ...
> >>> o=old()
> >>> o.z = f.__get__(o, old)
> >>> o.z
> <bound method old.f of <__main__.old instance at 0x53d78>>
> >>>
> There's a million reason to avoid using old-style classes in new code,
> but it doesn't seem to me that this is one of them.  What am I missing?
> Alex

More information about the Python-list mailing list