在python中将函数设置为布尔值
我正在用Python2.6编写一个驱动程序,我需要它与以前的实现反向兼容(我没有访问源代码的权限) 奇怪的是,为了保持兼容性,我必须使用在python中将函数设置为布尔值,python,Python,我正在用Python2.6编写一个驱动程序,我需要它与以前的实现反向兼容(我没有访问源代码的权限) 奇怪的是,为了保持兼容性,我必须使用 nd = new_driver() nd.output = True 如何以这种方式传递值 编辑:澄清:我的“输出”函数必须以这种方式接收值True才能执行函数本身。请使用@property装饰器设置输出打开() @property def output(self): return self... #not sure how you are trac
nd = new_driver()
nd.output = True
如何以这种方式传递值
编辑:澄清:我的“输出”函数必须以这种方式接收值True才能执行函数本身。请使用
@property
装饰器设置输出打开()
@property
def output(self):
return self... #not sure how you are tracking output on/off
@output.setter
def output(self, state):
if state:
self.set_output_on()
else:
self.set_output_off()
尝试使用
@属性
装饰器:
@property
def output(self):
return self... #not sure how you are tracking output on/off
@output.setter
def output(self, state):
if state:
self.set_output_on()
else:
self.set_output_off()
那么,您的接收者希望nd.output
是布尔值还是什么?为什么是2.6?你想把它传递到哪里?那么,你的接收者希望nd.output
是布尔值还是什么?为什么是2.6?你想把它传递到哪里呢?我对decorators做了一些研究(我是pythonnoob),但我并不真正理解内置的属性
函数是什么。此外,我了解@output
的可能用途,但对.setter
是/做什么感到困惑。我对decorators做了不少研究(我是python noob),但我并不真正理解内置的属性
函数是/做什么的。我也理解@output
的可能用途,但对.setter
是/做什么感到困惑。