how to keep collection of existing instances and return one on instantiation

Diez B. Roggisch deets at nospam.web.de
Wed Oct 5 12:28:12 EDT 2005


> What I *really* want is to keep a collection of all the Spam instances,
> and if i try to create a new Spam instance with the same contructor
> parameters, then return the existing Spam instance.  I thought new-style
> classes would do it:
<snip>

> So what is the best/preferred way to do this?

Use the BORG-pattern. See


http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531

Together with your caching, that should do the trick.

Diez



More information about the Python-list mailing list