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_attr must 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

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -