Package topo :: Package misc :: Module utils :: Class Singleton
[hide private]
[frames] | no frames]

Class Singleton

source code

object --+
         |
        Singleton
Known Subclasses:
ExtraPickler

The singleton pattern.

To create a singleton class, you subclass from Singleton; each subclass will have a single instance, no matter how many times its constructor is called. To further initialize the subclass instance, subclasses should override 'init' instead of __init__ - the __init__ method is called each time the constructor is called.

From http://www.python.org/2.2.3/descrintro.html#__new__



Instance Methods [hide private]
 
init(self, *args, **kwds)
Method to be overridden if the subclass needs initialization.
source code
 
__reduce_ex__(self, p)
Causes __new__ to be called on unpickling; in turn, __new__ ensures there is only one instance.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __init__, __reduce__, __repr__, __setattr__, __str__

Static Methods [hide private]
 
__new__(cls, *args, **kwds)
staticmethod(function) -> method
source code
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__new__(cls, *args, **kwds)
Static Method

source code 

staticmethod(function) -> method

Convert a function to be a static method.

A static method does not receive an implicit first argument. To declare a static method, use this idiom:

class C:
def f(arg1, arg2, ...): ... f = staticmethod(f)

It can be called either on the class (e.g. C.f()) or on an instance (e.g. C().f()). The instance is ignored except for its class.

Static methods in Python are similar to those found in Java or C++. For a more advanced concept, see the classmethod builtin.

Overrides: object.__new__
(inherited documentation)

__reduce_ex__(self, p)

source code 
Causes __new__ to be called on unpickling; in turn, __new__ ensures there is only one instance.
Overrides: object.__reduce_ex__