class Animal(object):
__slots__ = ('name','age')
def __init__(self,name,age):
self.__name = name
self.__age = age
@property
def name(self):
return self.__name
@name.setter
def name(self,value):
self.__name = value
d = Animal('Tom',12)
d.name = 'Alice'
print(d.name)
Error>>
AttributeError: 'Animal' object has no attribute '_Animal__name'如果我这样写的话会报错,那么如何正确实现slots 与 property?
添加回答
举报
0/150
提交
取消