gpt4 book ai didi

linux - Python DBus 返回空列表

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:16:07 25 4
gpt4 key购买 nike

我有一个返回字符串列表的 Python 2.7 DBus 方法。当列表不为空时,该方法有效。当它为空时,将抛出一个异常,指出“无法从空列表中猜测签名”。

方法如下:

@dbus.service.method('blecnx.comp.com.control', signature='as')
def getSlaveList(self):
global connectedSlaves
print("Interface:getSlaveList() getSlaveList called - length is: %s" % (len(connectedSlaves)))
if len(connectedSlaves) == 0:
return dbus.Array(dbus.Array([], signature='as'))
else:
return connectedSlaves

异常(exception)情况:

ERROR:dbus.service:Unable to guess signature for arguments (dbus.Array([], signature=None),): <type 'exceptions.ValueError'>: Unable to guess signature from an empty list

我试图更新 DBus 方法的签名以明确声明它是一个字符串数组,但没有帮助。

如何确保该方法不会抛出空列表异常?

最佳答案

原来你不能只指定“signature='as'”——它必须是“out_signature='as'”。

现在可以了。

关于linux - Python DBus 返回空列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51613016/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com