【发布时间】:2014-07-17 09:13:31
【问题描述】:
今天我正在查看另一个人的代码,并且看到了这个:
class A(B):
# Omitted bulk of irrelevant code in the class
def __init__(self, uid=None):
self.uid = str(uid)
@classmethod
def get(cls, uid):
o = cls(uid)
# Also Omitted lots of code here
cls() 函数在这里做什么?
如果我让其他一些类继承了这个A类,调用它C,当调用这个get方法时,这个o会使用C类作为cls()的调用者吗?
【问题讨论】:
-
cls在这种情况下是A。