我有一堂课 Vertex()
使用以下方法:
def __new__(cls, pos_x, pos_y, size_x, size_y, text):
instance = super(Vertex, cls).__new__(cls)
#print 'variables {0}, {1}, {2}, {3}, {4}'.format(pos_x, pos_y, size_x, size_y, text)
#print instance.__class__.__name__
return instance
def __init__(self, pos_x=None, pos_y=None, size_x=None, size_y=None, text=None):
print 'init'
super(Vertex, self).__init__()
在另一个类的方法中,我有个电话:
self.vertices[touch.uid] = Vertex(pos_x=self.bounds[3][0], pos_y=self.bounds[2][1], size_x=self.bounds[1][0] - self.bounds[3][0], size_y= self.bounds[0][1] - self.bounds[2][1], text=None)
其行为符合预期,并Vertex()
通过同时调用__new__()
和__init__()
但是,当我解开一个方法时,将调用Vertex()
该__new__()
方法,但不会调用该__init__()
方法。我检查了一下,并且在取消选择该实例的类时Vertex
,据我所知__init__()
应该调用它。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句