voglioPython: @staticmethod con @property
Stats.singleton.twitter_count += 1
e ho pensato che avrei potuto fare
class Stats:
singleton_object = None
@property
@staticmethod
def singleton():
if Stats.singleton_object:
return Stats.singleton_object
Stats.singleton_object = Stats()
return Stats.singleton()
Ma viene generata un'eccezione:
>>> 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)
dove è definito 'singleton_object'? – tonfa
dove è definito 'self'? – tonfa
define "not working" – u0b34a0f6ae