singleton problems

harryos oswald.harry at
Sun Oct 3 10:55:00 CEST 2010

I have been trying out singleton design pattern implementations..I
wrote this,

class Singleton(object):
    _instance = None
    def __new__(self, *args, **kwargs):
        if not self._instance:
            self._instance = super(Singleton, self).__new__(self,
*args, **kwargs)
        return self._instance

class Mysingle(Singleton):
    def __init__(self,name):

if __name__=='__main__':
    print 's1=',s1,
    print 's2=',s2,
    print 's3=',s3,

This is the result I got
s1= <__main__.Mysingle object at 0xb776492c> jeff
s2= <__main__.Mysingle object at 0xb776492c> jeff
s3= <__main__.Mysingle object at 0xb776492c> jeff
DeprecationWarning: object.__new__() takes no parameters
  self._instance = super(Singleton, self).__new__(self, *args,

shouldn't the name of s1,s2,s3 be 'john' instead of 'jeff'?
Also,how do I correct the deprecation problem?Can somebody comment?

More information about the Python-list mailing list