Singleton vs Proxies DP (was Re: Solution: Direct access to Printer I/O lines)

Rainer Deyke root at rainerdeyke.com
Sun Dec 17 12:22:35 EST 2000


"Andrew Dalke" <dalke at acm.org> wrote in message
news:91hrbn$v7a$1 at slb3.atl.mindspring.net...
> Rainer Deyke wrote:
> >My preference for standardized singletons in Python is this:
> >
> >singleton C:
> >  pass # class definition here
> >
> >The singleton statement would be equivalent to the following:
> >
> >class __tmp:
> >  pass # class definition here
> >C = __tmp()
> >del __tmp
>
> Wouldn't the cleaner equivalent be
>
> class C:
>   pass
> C = C()

Good point.

> If that's the case, do we really need a new keyword for
> what can be done with one extra line of code and no new
> functionality?

Well, no, we don't actually *need* a new keyword.  If you have lots of small
singletons, the above idiom is still somewhat cumbersome.


--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list