此问题与this other one类似,不同之处在于基类中的数据成员是而不是由描述符协议包装。 换句话说,如果我用派生类中的属性重写它的名称,我该如何访问基类的成员? class Base(object):
def __init__(self):
self.foo = 5
class Derived(Base):
def __init__(self):
我试图学习描述符,并且被对象行为困惑 - 在下面的两个示例中,正如我理解的__init__他们应该工作一样。有人可能会否认我,或者指出一个解释这一点的资源? import math
class poweroftwo(object):
"""any time this is set with an int, turns it's value to a tuple of the int
我想在python中创建一个具有几个属性的对象,并且我想保护自己不会意外地使用错误的属性名称。代码如下: class MyClass(object) :
m = None # my attribute
__slots__ = ("m") # ensure that object has no _m etc
a = MyClass() # create one
a.m =