http://code.activestate.com/recipes/52558-the-singleton-pattern-implemented-with-python/ How is the above singleton? By the time u r in init, a new instance has already been created!!!
It’s not real singleton. It’s a class that associates and forwards to a singleton. You can create multiple instances of the outer class.
Yes precisely
You use a static or class variable, no? I always get the damn two confused.
Why should this be in Blind
Why do you need a Singleton.
This code is ancient. Notice that this is an old-style class back when it was, well, just a class. You could not (then) override __new__. The best you could hope for was a proxy with forwarding
What would be the better version today?
There are a couple ways to play the factory trick. The easiest and best way is to override new. This controls the actual instance returned by the type constructor. Have to do initialization there and gut __init__. This is how tuple ctor works (kinda). Another way to slice it would be to use a class decorator to create a factory (has the down side of hiding the type)
That's ugly code