afriere at yahoo.co.uk
Thu Jul 17 05:05:47 CEST 2008
On Jul 17, 8:20 am, Craig Allen <callen... at gmail.com> wrote:
> Is it pythonic?
You probably can't get anymore pythonic than something written by the
BDFL. In describing the use of __new__ in <i>Unifying types and
classes in Python 2.2</i> he gives this recipe for a Singleton.
def __new__(cls, *args, **kwds):
it = cls.__dict__.get("__it__")
if it is not None:
cls.__it__ = it = object.__new__(cls)
def init(self, *args, **kwds):
You might find this a useful starting point.
More information about the Python-list