How can a python object's classmethods be referred to inside the class attributes? -
i along lines of...
class myclassa(object): an_attr = anotherclassb(do_something=myclassa.hello) @classmethod def hello(cls): return "hello" however tell me myclassa not defined when try run it.
an_attrmust class attribute- i can't alter
anotherclassb - i prefer if
hello()remained classmethod
any ideas?
you have order right, it's defined before use it:
class myclassa(object): @classmethod def hello(cls): return "hello" an_attr = anotherclassb(do_something=hello) note that, because it's in namespace when we're creating class, refer hello, not myclassa.hello.
edit: sorry, doesn't thought did. creates class without error, anotherclassb gets reference unbound classmethod, can't called.
Comments
Post a Comment