class Something(object):
our_random = Something.random_thing
@staticmethod
def random_thing():
return 4
當然,這不起作用,因爲當我嘗試調用它的方法時,某些東西不存在。也沒有這樣的:設置類屬性時引用方法
class Something(object):
our_random = random_thing
@staticmethod
def random_thing():
return 4
我「解決」這僅通過將random_thing()的定義類以上,但我覺得這是凌亂。
您是不是要調用'random_thing'? –