[Python-Dev] Re: Python-Dev Digest, Vol 8, Issue 91

Greg Ewing greg at cosc.canterbury.ac.nz
Tue Mar 30 20:47:50 EST 2004


Edward Loper <edloper at gradient.cis.upenn.edu>:

> On a related note, now that Python has class methods, is there much 
> point in a "singleton" pattern?  In particular, why not just make a 
> class that only defines class methods, and uses the class namespace to 
> store variables (instead of an instance namespace)?

Classes do various magic things on attribute lookups that you might
not want for an object that isn't meant to be used as a class.

For a while I've been wondering whether Python should have
an "instance" statement that's analogous to "class" but creates
an instance instead, e.g.

  instance fred(Foo):
    blarg = 42
    def f():
      do_something()

would be equivalent to something like

  class _fred(Foo):
    def f():
      do_something()
  fred = _fred()
  fred.blarg = 42

People working on interactive fiction would love something
like this, I expect.

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg at cosc.canterbury.ac.nz	   +--------------------------------------+



More information about the Python-Dev mailing list