singleton objects with decorators
Bengt Richter
bokr at oz.net
Tue Apr 12 07:20:05 EDT 2005
On 12 Apr 2005 03:09:48 -0700, "Michele Simionato" <michele.simionato at gmail.com> wrote:
>Steven Bethard:
>> It strikes me that I've never wanted or needed a singleton object.
>> Would you mind sharing your use case? I'm just curious.
>
>"Singleton" is the most idiotic pattern ever. If you want an instance,
>just
>instantiate your class once. If a class should have only one instance,
>you can just document it. What I find usuful is "memoize", which
>contains "Singleton" as a special case. So I use memoize even
>for singleton would-be, i.e. logfiles and databases connections
>(memoizing the connections, if I try to open a database twice with the
>same parameters, I am returned an instance of the already opened
>database).
>
For most user application purposes, I agree,
just use a single instance like a responsible adult ;-)
But isn't bool supposed to be a singleton class/type ?
>>> [bool(x) for x in 0, 0.0, [], {}, False]
[False, False, False, False, False]
>>> [id(bool(x)) for x in 0, 0.0, [], {}, False]
[505014288, 505014288, 505014288, 505014288, 505014288]
Regards,
Bengt Richter
More information about the Python-list
mailing list