the singleton pattern in the __new__ functionwe see that whenever programmer tries to instantiate an object of type singletonobjectthe interpreter will first check the class variable instance to see if there is such an instance in existence if there is no existing instanceit creates new instance of the private class and assigns it to the instance class variable finallythe __new__ function returns the class in the instance class variable we also alter the __getattr__ and __setattr__ functions to call the attributes found in the private class saved in the instance class variable this relays the call to the object housed in the instance variable as if the outer object has the attributes the self val attribute is set just to show that the object remains the same even though the script attempts to instantiate it more than once good--now you can use the class to verify that the singleton implementation does what you would expect it to do test_singleton py from singleton_object import singletonobject obj singletonobject(obj val "object value print("print obj "obj print(""obj singletonobject(obj val "object value print("print obj "obj print("print obj "obj here is the outputprint obj <__main__ singletonobject __singletonobject object at fda def object value ----print obj <__main__ singletonobject __singletonobject object at fda def object value print obj <__main__ singletonobject __singletonobject object at fda def object value