linux - Python DBus 返回空列表

标签 linux python-2.7 dbus

我有一个返回字符串列表的 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/

相关文章:

python - Python 中有没有流行的库来监控 Linux/Unix 系统?

python - 我想运行像 make , make install 和 python setup install 这样的命令

css - 如何在 GtkScrollbar 上设置最小宽度?

c - g_bus_get_sync 返回 NULL 但 dbus_g_bus_get_private 有效

linux - 如何在 shell 脚本中使用 grep 在文件中查找单词

c - SIGINT 信号后进程终止

Python Pandas : Combine two dataframes by date index and a common column value

python - 终端 - 如何覆盖多行?

c - 我怎样才能让 g_dbus_connection_signal_subscribe 函数告诉我预先存在的对象/接口(interface)?

DBUS- "Service"和 "Bus name"的差异