Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中将函数设置为布尔值_Python - Fatal编程技术网

在python中将函数设置为布尔值

在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

我正在用Python2.6编写一个驱动程序,我需要它与以前的实现反向兼容(我没有访问源代码的权限)

奇怪的是,为了保持兼容性,我必须使用

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
是/做什么感到困惑。