[Tutor] Problem with calling class methods stored in a list
eryksun
eryksun at gmail.com
Thu Jan 10 13:57:35 CET 2013
On Thu, Jan 10, 2013 at 7:11 AM, Steven D'Aprano <steve at pearwood.info> wrote:
>
> So, inside the foo() method, do this:
>
> @classmethod
> def foo(cls):
> cls.method_list[0].__get__(cls, None)()
That should be
cls.method_list[0].__get__(None, cls)()
The way you have it binds the method to type(MyClass), which in this
case is "type" itself. See cm_descr_get in funcobject.c, CPython 2.7
(line 645):
http://hg.python.org/cpython/file/70274d53c1dd/Objects/funcobject.c#l635
Also see the slot wrapper wrap_descr_get for the mapping from None to
NULL (line 4671):
http://hg.python.org/cpython/file/70274d53c1dd/Objects/typeobject.c#l4660
More information about the Tutor
mailing list