On Thu, Jan 10, 2013 at 11:13 AM, Tobias Marquardt <t...@tobix.eu> wrote:
> 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? > > Why do you need the method list at all? if you simply get rid of that and call cls.bar() you would be rid of the problem entirely. What piece of your code requires this list? Perhaps we can redesign that to be rid of it. Hugo
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor