Hello,

I have a class with some class methods that are also stored in a list.
Now I have a problem calling these methods.
Essentially the relevant code looks like this:

class MyClass(object):

    @classmethod
    def foo(cls):
        cls.method_list[0]()

    @classmethod
    def bar(cls):
        print("Hello World")

    method_list = [bar]


So foo() takes bar() from the list and tries calls it, which results in
an error:

File "aco/antsystem/test.py", line 11, in foo
    cls.method_list[0]()
TypeError: 'classmethod' object is not callable

I guess the reason is that bar() needs to be called on the class like:
cls.bar(), but how to I achieve this here?
Any suggestions?

Tobias




_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to