I'm using a singleton for a python class like the following example
class GestionnaireUtilisateur(object):
__singleton = None
def __new__(cls, *args, **kwargs):
if not cls.__singleton:
cls.__singleton = super(GestionnaireUtilisateur, cls).__new__(cls, *args, **kwargs)
return cls.__singleton
def __init__(self):
self.compte = None
I can modifie self.__compte with the following method
def connexion(self, compte):
self.compte = compte
On my first object GestionnaireUtilisateur(), I call the method connexion('toto') to modifie self.compte and the result is good. But when I call an another time the GestionnaireUtilisateur(), the self.compte is at None and not at the value I'm passing by connexion().
I make a test to not if the object are the same and they are. I have this result
<securecloud.utilisateur.gstutilisateur.GestionnaireUtilisateur object at 0xb73aad4c>
toto
<securecloud.utilisateur.gstutilisateur.GestionnaireUtilisateur object at 0xb73aad4c>
None
Someone have an idee?