Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有subprocess.call的Python unicode问题_Python_Unicode_Subprocess_Python Unicode - Fatal编程技术网

带有subprocess.call的Python unicode问题

带有subprocess.call的Python unicode问题,python,unicode,subprocess,python-unicode,Python,Unicode,Subprocess,Python Unicode,我的解析器函数使用lxml,并为我提供unicode字符串列表(book\u list) 这些字符串被合并成一个文件名,经过清理,然后通过子流程传递给另一个二进制文件,继续工作 我的问题是unicode对象(例如,title\u name=u'Wunderlicher Traum von einem gro\xdfen Narrennest')是用ISO-8859-2编码的(至少这是“chardet”告诉我的),我需要将它们转换成一种格式,在文件系统级别上正确显示。当前代码导致文件名为u'Wun

我的解析器函数使用
lxml
,并为我提供unicode字符串列表(
book\u list

这些字符串被合并成一个文件名,经过清理,然后通过
子流程传递给另一个二进制文件,继续工作

我的问题是unicode对象(例如,
title\u name=u'Wunderlicher Traum von einem gro\xdfen Narrennest'
)是用ISO-8859-2编码的(至少这是“chardet”告诉我的),我需要将它们转换成一种格式,在文件系统级别上正确显示。当前代码导致文件名为
u'Wunderlicher Traum von einem gro\xc3\x9fen Narrennest'

有人知道我做错了什么吗

一些信息:

  • sys.getdefaultencoding()
  • OS X 10.9、Python 2.7.5


在写下问题后,发布问题的原因要清楚:)

  • \xdf
    是UTF-8
  • \xc3\x9f
    是ISO-8859-1或拉丁语-1
我所要做的就是将utf-8对象转换为latin-1对象,然后将参数传递给subprocess.call

out_enc = 'latin-1'
engine_parameter = [arg.encode(out_enc) if isinstance(arg, unicode) else arg for arg in engine_parameter]
call(engine_parameter)
希望这能帮别人省去头痛

out_enc = 'latin-1'
engine_parameter = [arg.encode(out_enc) if isinstance(arg, unicode) else arg for arg in engine_parameter]
call(engine_parameter)