« Celestial Jukebox in Japan and South Korea? | Main | More on Eolas »

March 15, 2004

Another Python Singleton version

I've improved the Python singleton class I was working on. A comment on my blog mentioned metaclasses, and somebody else editing the wiki mentioned __new__. I've incorporated both into a new version that I think is getting to be pretty solid. If you're interested in such things, you may want to check it out. Again, comments are welcome.

March 15, 2004 in Web/Tech | Permalink

Comments

The "singletons" I've created to date never are confusing w.r.t. whether or not they were "created" or they were "singletons", so that's why my solution just tapped into __new__ directly. Really, I just use them when I want to say "is" instead of ==. It may even qualify as a pre-mature optimization since I'm often trying to save memory vs. having hundreds or thousands of otherwise identical objects in memory, not to mention construction and destruction costs.

Nice unification work.

Posted by: Jeremy Bowers at Mar 15, 2004 2:33:23 PM

Note, the blog post that will be used to keep track of the singleton issue on my blog is my original post on the subject -- please leave any further comments there.

Posted by: Gary Robinson at Sep 28, 2004 8:49:35 AM

Post a comment