singleton objects with decorators

Steven Bethard steven.bethard at gmail.com
Tue Apr 12 10:49:24 EDT 2005


Uwe Mayer wrote:
> Tuesday 12 April 2005 10:01 am Steven Bethard wrote:
> 
>>>I am using a class to manage configuration settings in an application.
>>>This object should only existe once so that when the user
>>>changes a setting through a configuration dialog the change imminent in
>>>all locations where access to config settings are needed.
> 
>>Ahh, I see.  I would typically just use a module in this situation,
>>where the configuration settings were just names global to the module.
>>Is there a benefit to using a singleton object over using just a module?
> 
> Basically I am using a module. The config file is stored in
> $HOME/.<app>/<app>.conf where the user can go and edit it. It is a working
> python program which globally declares variables.
> I cannot simply import this module as it does not lie in the path and I am
> not too fond of dynamically cluttering sys.path to my needs.

Hmmm...  Maybe you could use a memoized wrapper to imp.load_source? 
I've never used it, but it looks kinda like it might do what you want...

But I guess that probably doesn't really gain you too much over the 
Singleton solution...

STeVe



More information about the Python-list mailing list