|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
class A:
def __init__(self,x=10):
self.x = x
def g(self):
return x
def s(self,va):
self.x = va
def d(self):
del self.x
x = property(g,s,d)
>>>
>>>
>>> a = A()
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
a = A()
File "<pyshell#1>", line 3, in __init__
self.x = x
File "<pyshell#1>", line 7, in s
self.x = va
File "<pyshell#1>", line 7, in s
self.x = va
File "<pyshell#1>", line 7, in s
self.x = va
[Previous line repeated 491 more times]
RecursionError: maximum recursion depth exceeded while calling a Python object
>>>
property()传入的三个函数应当是围绕一个属性的一套操作
不过楼主代码本身有两个问题:
1、第5行应该是return self.x ,小问题
2、第10行property()返回的对象和要操作的属性重名了,把第10行的x改个名字就好
|
|