First of all i would like to state that i am fairly new to Python programming, therefore my approach to solving the problem maybe incorrect, please let me know if that is the case
I am trying to use a Singleton class to store configuration params in my code and use it when needed. I run into an issue that the data stored in the Singleton in the initial creation is not retained in the subsequent calls to the Object.
Maybe the way i create the Singleton object is incorrect, but i was following the code samples that was on SO.
first here is my Singleton class
class Config(object):
__instance = None
dbserver = ""
def __new__(cls):
if cls.__instance == None:
__instance = object.__new__(cls)
__instance.name = "Configuration Object"
return __instance
Here is my initial creation of the Singleton instance
configurator = Config()
configurator.dbserver = dbserver
then subsequently i do the following and dbserver
property returns empty string.
configurator = Config()
print configurator.dbserver
Thanks for your time reading.