重载如下类:
- class Position(object):
 -     def __init__(self, x = None, y = None):
 -         self.x = x
 -         self.y = y
 -         pass
 -  
 -     def getX(self):
 -         return self.x
 -  
 -     def getY(self):
 -         return self.y
 -  
 -     def setX(self, x):
 -         self.x = x
 -         pass
 -  
 -     def setY(self, y):
 -         self.y = y
 -         pass
 -  
 -     def __repr__(self):
 -  
 -         return '(%d,%d)'%(self.x if self.x else -1, self.y if self.y else -1)
 -         pass
 -  
 -     pass
 
 
Python中的单例:
- class CvGraph(object):
 -     instanceLock = threading.Lock()
 -     def __init__(self):
 -         pass
 -  
 -     def __new__(cls, *args, **kwargs):
 -         if not hasattr(CvGraph, "instance"):
 -             with CvGraph.instanceLock:
 -                 if not hasattr(CvGraph, "instance"):
 -                     CvGraph.instance = object.__new__(cls)
 -                     pass
 -                 pass
 -             pass
 -         return CvGraph.instance
 -         pass
 -     pass
 
 
                
                

















