求助
>>> class duck():def __int__(self,input_name):
self.hidden_name = input_name
def get_name(self):
print('inside the getter')
return self.hidden_name
def set_name(self,input_name):
print('inside the setter')
self.hidden_name = input_name
name = property(get_name,set_name)
>>> fowl = duck('hello')
最上面的类,为啥不能执行下面的代码。老显示错误提示。
Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
duck('hello')
TypeError: object() takes no parameters
求助谢谢哇。{:5_94:} 不好意思啊,我打错了个int,我改成了init了,还是不能执行,问题是一样的。 改成 init 就没有问题了哈~
>>> class duck():
def __init__(self,input_name):
self.hidden_name = input_name
def get_name(self):
print('inside the getter')
return self.hidden_name
def set_name(self,input_name):
print('inside the setter')
self.hidden_name = input_name
name = property(get_name,set_name)
>>> fowl = duck("hello")
>>> fowl.name
inside the getter
'hello'
>>> fowl.name = "FishC"
inside the setter
>>> fowl.name
inside the getter
'FishC'
页:
[1]