singleton objects with decorators

James Stroud jstroud at mbi.ucla.edu
Tue Apr 12 20:48:00 EDT 2005


Other than using modules, I thought @classmethod took care of this kind of 
need:

class SingleThing:
  some_values = {"fanciness":0}
  def __init__(self):
    raise Exception, "not enough preceding stars to be fancy enough"
  @classmethod
  def why_so_fancy(self):
    print "why make every thing so fancy?"

I call this pattern:

"Using a Class to Be Something Single Because It Already Is Single"

or "uactbssbiais", for short.

James

-- 
James Stroud, Ph.D.
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/



More information about the Python-list mailing list