【发布时间】:2015-10-26 18:04:10
【问题描述】:
我正在使用KISS Python 模块从串行通信端口收集数据。 这个模块有一个函数,它返回从串口获取的值的值。得到模块源代码的代码行如下:
for frame in frames:
if len(frame) and ord(frame[0]) == 0:
self.logger.debug('frame=%s', frame)
self.logger.debug('hola soy el logger debug')
if callback:
callback(frame)
我正在尝试将 frame 的值存储在一个变量中。我需要在通过继承类QThread 的对象创建的线程中进行操作。我正在使用 PyQt4 制作应用程序。
类如下:
class OperativeKISSThread(KISSThread):
def __init__(self, parent = None):
KISSThread.__init__(self, parent)
def doWork(self):
prueba.read(callback=self.catchValue(frame))
return True
def catchValue(self, frame):
print frame
当我运行上面的代码时,我得到以下屏幕输出:
Traceback (most recent call last):
File "_client_amp.py", line 432, in run
success = self.doWork(self.kissTNC)
File "_client_amp.py", line 452, in doWork
prueba.read(callback=self.catchValue(frame))
NameError: global name 'frame' is not defined
为了获取 frame 的值,我的代码会做哪些更改?
【问题讨论】:
标签: python python-2.7 pyqt4