0
是否可以将@property
函数存储在变量中?存储@property函数
假设我们有下面的代码:
class I:
def __init__(self):
self.i = 0
def get_i(self):
return self.i
a = I()
f_i = a.get_i
print(f_i())
a.i = 3
print(f_i())
我保存功能get_i一个变量中,并使用它。如预期的输出:
0
3
现在让我们看看相同的代码,但这次的@property
功能:
class I:
def __init__(self):
self.i = 0
@property
def get_i(self):
return self.i
a = I()
f_i = a.get_i
现在a.get_i
不是功能了(这是值0) 。有什么方法可以将函数仍然存储在f_i变量中吗?
'I.get_i.fget .__获取__(一)'就是我正在寻找的。谢谢! – BlueSun