-1
我建立了一个类来处理很多不同的函数,它们采用通用输入。但是,我刚碰到需要更改通过self
反馈的变量之一的情况。我该怎么做呢?这是一个例子:类变量更新
class Test:
def __init__(self, test_variable):
self.test_var = test_variable
@property
def some_function(self):
if self.test_var < 0:
self.test_var = 'New Output' #this is the line that I can't get
#get to work and I was hoping to update it here
#so I could use it in later functions
return self.test_var
谢谢!
究竟什么是您遇到的问题?据我所知,您发布的代码完全符合您的期望。 –
请注意,如果你想'self.test_var',你可以调用'self.some_function'。 –
除了不能多次调用'some_function'之外,'test_variable'最初是否定的,这是什么问题? – James