singleton objects with decorators
Fredrik Lundh
fredrik at pythonware.com
Tue Apr 12 04:16:14 EDT 2005
Uwe Mayer wrote:
>> It strikes me that I've never wanted or needed a singleton object.
>> Would you mind sharing your use case? I'm just curious.
>
> 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.
So use a module-level object, and be done with it.
Or if you're using an application object (you should), just add a config object
to the application object (app.config.param = ...).
Or use a module to hold the configuration data (import config; config.param = ...);
serializing to and from module variables work really well in Python.
> I was using a factory function bevore, but since I am starting to use Python
> 2.4 and I remembered having read about a singleton-decorator I went to look
> deeper into the possibilities.
I'm sure your users would love you even more if you spend that time and
energy adding stuff to the application... ;-)
</F>
More information about the Python-list
mailing list