Singleton class: what is the purpose?
Just
just at xs4all.nl
Thu Jun 5 08:54:43 EDT 2003
In article <just-EE6BC0.14300805062003 at news1.news.xs4all.nl>,
Just <just at xs4all.nl> 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__.)
Just
More information about the Python-list
mailing list