我知道这个问题可能看起来很愚蠢,但我真的无法弄明白。我天真地认为字符串序列是字符串列表。然而,这失败了:
(pid, stdin, stdout, stderr) = glib.spawn_async(
argv=["foo", "bar"],
envp=None,
flags=glib.SPAWN_SEARCH_PATH + glib.SPAWN_CHILD_INHERITS_STDIN,
standard_input=True,
standard_output=True,
standard_error=True)
失败并出现此错误:
TypeError: glib.spawn_async: first argument must be a sequence of strings
我尝试了一个元组,但没有提供更好的结果。
如果不是列表,什么是字符串序列?我想到了一个可能的 Python‑Glib 错误,但我不相信这样的错误真的存在。我在网上发现了类似的消息,但我不知道这是一个错误的错误,还是一个错误的发生。
-- 编辑--
使用这个更短的样本,结果相同:
(pid, stdin, stdout, stderr) = glib.spawn_async(argv=["foo", "bar"])
应海报要求,这里是完整的跟踪:
Traceback (most recent call last):
File "<...>/test.py", line 92, in <module>
run()
File "<...>/test.py", line 62, in run
standard_error=True)
TypeError: glib.spawn_async: first argument must be a sequence of strings
最佳答案
总结对问题的评论:
- 字符串不应该是 unicode 对象。如果您有 Python 3 或
from __future__ import unicode_literals
,请通过b"foo"
语法生成字节文字。 envp
参数似乎与其文档有所不同。不要向它提供 None 。如果您不打算使用它,请不要提供该关键字/位置。
关于python - 在 Python 中,字符串序列到底是什么? (或者 Glib 错误?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21792231/