singleton ... again

Gregory Ewing greg.ewing at canterbury.ac.nz
Fri Feb 14 00:06:44 EST 2014


Steven D'Aprano wrote:
> On Wed, 12 Feb 2014 23:04:32 +1300, Gregory Ewing wrote:
> 
>>If you really want to make sure nobody creates another instance by
>>accident, delete the class out of the namespace after instantiating it.
> 
> That does not work. It is trivial to get the type from an instance:

I said *by accident*. Of course it's nearly impossible
to prevent someone who is determined enough from making
another instance, but it will prevent them from doing
so by mistake, if, e.g. they fail to notice the line
in the docs that says "don't try to instantiate this
directly, use the factory function".

-- 
Greg



More information about the Python-list mailing list