百思不得骑姐
做练习时参照做了一个测试,代码如下:class C:
def __init__(self,x=10):
self.x=x
def getxy(self):
return self.x
def setxy(self,value):
self.x=value
def delxy(self):
del self.x
x=property(getxy,setxy,delxy)
实例化c1=C()时会报错:
>>> c1=C()
Traceback (most recent call last):
File "<pyshell#55>", line 1, in <module>
c1=C()
File "C:/Users/MOMO/Desktop/1.py", line 3, in __init__
self.x=x
File "C:/Users/MOMO/Desktop/1.py", line 7, in setxy
self.x=value
File "C:/Users/MOMO/Desktop/1.py", line 7, in setxy
self.x=value
File "C:/Users/MOMO/Desktop/1.py", line 7, in setxy
self.x=value
RecursionError: maximum recursion depth exceeded
>>>
把参数x换成其他字符就没问题,用x就不行。
百思不得骑姐。
求各位大侠指点 让各位大侠见笑了,原来是x=property这里有了x,引用报错了
页:
[1]