|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
代码是这样的class Rectangle:
def __init__(self,width=0,height=0):
self.width = width
self.height = height
def __setattr__(self, nanme, value):
if name == 'square':
self.width = value
self.height = value
else:
super().__setattr__(name,value)
def getArea(self):
return self.width * self.height
然后就报错了,根据视频教程写的啊,错误提示是这样的:
Traceback (most recent call last):
File "<pyshell#61>", line 1, in <module>
r1 = Rectangle(4,.5)
File "E:\Python\lianxi.py", line 78, in __init__
self.width = width
File "E:\Python\lianxi.py", line 82, in __setattr__
if name == 'square':
NameError: name 'name' is not defined |
|