[Python-Dev] PEP 318: Singleton decorator (original) (raw)

Skip Montanaro skip at pobox.com
Thu Apr 8 17:31:07 EDT 2004


>> But i don't think this is a good way to write a singleton, because
>> then the user of the class has to get instances by saying "MyClass"
>> instead of "MyClass()".

Phillip> That's a stylistic decision.  IMO, it's more pythonic to *not*
Phillip> call a constructor.  One does not, after all, call modules in
Phillip> order to "construct" them, and modules are a prime example of
Phillip> singletons in Python.

I think Ping's point is that if the user thinks Foo is a class, he's going to want to instantiate it like Foo(). Whether or not you get back a new instance or an existing one is sort of beside the point. It's simply a consistency issue.

Skip



More information about the Python-Dev mailing list