Je veuxPython: @staticmethod avec @property
Stats.singleton.twitter_count += 1
et je pensais que je pouvais faire
class Stats:
singleton_object = None
@property
@staticmethod
def singleton():
if Stats.singleton_object:
return Stats.singleton_object
Stats.singleton_object = Stats()
return Stats.singleton()
Mais il renvoie une exception:
>>> Stats.singleton.a = "b"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'property' object has only read-only attributes (assign to .a)
où 'singleton_object' est-il défini? – tonfa
Où est défini "self"? – tonfa
définir "ne fonctionne pas" – u0b34a0f6ae