"Frans Englich" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]

Hello,

[...]


What the code attempts to do is implementing a, to the API user, transparent
memory-saver by ensuring that no more than one instance of the class foo
exists for a particular id. E.g, the user can simply "create" an instance and
if one not already exists, it is created.

In other words, you're trying to create a singleton. In general, singletons are frowned on these days for a number of reasons, not least because of the difficulty of testing them.

First of all; am I approaching the goal with the right solution?

No. In all Python releases since 2.2, the correct way of doing this is to use the __new__() method. Unfortunately, the only place it is documented is here:

http://www.python.org/2.2.3/descrintro.html

and here:

http://users.rcn.com/python/download/Descriptor.htm

The first reference contains an example of how to do
a singleton: simply search on the word Singleton.

John Roth

Cheers,

Frans





-- http://mail.python.org/mailman/listinfo/python-list

Reply via email to