In article <[EMAIL PROTECTED]>,
 meelab <[EMAIL PROTECTED]> wrote:

> Dear All,
> 
> I am looking for a way to create a "static object" or a "static class" -
> terms might be inappropriate - having for instance:
> 
> class StaticClass:
>     .
>     .
> 
> and then
> staticObject1 = StaticClass()
> staticObject2 = StaticClass()
> 
> so that staticObject1 and staticObject2 refers exactly to the same
> instance of object.

Personally I do the following (in its own module). There may be a better 
way, but this is simple and it works:

_theSingleton = None

def getSingleton():
   global _theSingleton
   if not _theSingleton:
      _theSingleton = _Singleton()
   return _theSingleton

class _Singleton:
   def __init__(self, ...):
      ...


-- Russell
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to