Python Singleton

#!/usr/bin/python

class Singleton( object ):
        instance = None
        def __new__( className, *args, **kargs):
                print 'Getting %s instance' % className.__name__
                if className.instance is None:
                        print 'Creating new %s object' % className.__name__
                        className.instance = object.__new__( className, *args, **kargs );
                return className.instance
 Continue reading 
Advertisements