Singleton class: what is the purpose?

Just just at
Thu Jun 5 14:54:43 CEST 2003

In article <just-EE6BC0.14300805062003 at>,
 Just <just at> wrote:

> It's not about enforcing it to be called only once, it's about 
> guaranteeing you always get the same instance. Here's a Singleton object 
> I recently wrote (it's simpler than Guido's -- I don't quite understand 
> why he's mucking with __dict__ and adds an init() method):
[ ... ]

Ha, I do now (learn something everyday!): you have to add a special init 
method if you're using __new__ like that: Python will call __init__ for 
you, *everytime* you call the class. (I find that a bit of a wart, I'd 
think that __new__ would be responsible for calling __init__.)


More information about the Python-list mailing list