Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Gregory Ewing Newsgroups: comp.lang.python Subject: Re: singleton ... again Date: Fri, 14 Feb 2014 18:06:44 +1300 Lines: 17 Message-ID: References: <52fc34e5$0$11128$c3e8da3@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net OpImLH7mAOs+qAvGSrTdHgFAQ4bABXngeuRKIT60FFKpV9Wtjy Cancel-Lock: sha1:SqkEkTDxFPnTWEHTutm+fPfCpeE= User-Agent: Mozilla Thunderbird 1.0.5 (Macintosh/20050711) X-Accept-Language: en-us, en In-Reply-To: <52fc34e5$0$11128$c3e8da3@news.astraweb.com> Xref: csiph.com comp.lang.python:66280 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