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

Andrew Dalke dalke at acm.org
Sun Dec 17 08:53:41 CET 2000


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()

 ?

In that way the class name used by the default repr would
still show a 'C' and you would have the nagging worry of
accidentally affecting someone else's use of __tmp in the
current namespace.  It also looks cleaner.

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?

                    Andrew Dalke
                    dalke at acm.org






More information about the Python-list mailing list