singleton decorator

Pedro Werneck pedro.werneck at terra.com.br
Wed Aug 9 08:40:37 EDT 2006


On Tue, 08 Aug 2006 14:50:39 +0200
Wildemar Wildenburger <wildemar at freakmail.de> wrote:

> Or you could always just use the __new__() method instead of
> __init__(),  putting all your initialization into the above
> except-block. If you  replace 'cls._it = ...' with 'self = cls_it =
> ...' you'll feel right at  home too :).
> 
> Anything 'unpythonic' (gosh how I hate that word ;)) about that, BTW?

Yes. :)

You'll have to make a custom Singleton class for each subclass you want
to make a singleton, instead of just creating a custom _init method for
each one of them.

You can use the subclass __new__, but that's definitely 'unpythonic'. 

-- 
Pedro Werneck



More information about the Python-list mailing list