返回我在report
函数中构建的字典时遇到一些问题。我知道我实际上在调用decode
函数。我就是不知道怎么解决这个问题。一切正常。代码做了它应该做的。但是后来,我添加了这个我想返回的字典,这样我就可以在script_A.py
中使用它
调用代码(sript_A.py):
self.decoder = Decoder(Frame)
recvDict = self.decoder.decode(self.message)
print type(recvDict) # this returns <type 'NoneType'>
调用代码(script_B.py):
^{pr2}$定义processIncomingPacket
的其他脚本:
class Some_class(object):
processIncomingPacket(self, data, callback):
raise NotImplementedException("not implemented")
更新:
processIncomingPacket
的实现:
def processIncomingPacket(self, data, callback):
_logger.debug(" ".join([hex(ord(x)) for x in data]))
self.addToFrame(data)
while self.isFrameReady():
if self.checkFrame():
result = self.decoder.decode(self.getFrame())
if result is None:
raise PacketIOException("Unable to decode request")
self.populateResult(result)
self.advanceFrame()
callback(result) # defer or push to a thread?
else: break
processIncomingPacket似乎什么也没做,只是引发了一个异常。在
我相信您需要修复processIncomingPacket的实现,以便对传递的参数执行操作并返回字典。在
问题是
processIncomingPacket
没有返回传递给它的回调的结果(self.result
,在您的例子中):最简单的修复方法是调整回调的工作方式,这样它就不需要返回任何东西。相反,让它获取一个现有的dict对象,然后用您想要的内容更新它:
^{pr2}$相关问题 更多 >
编程相关推荐