【发布时间】:2011-07-28 05:01:20
【问题描述】:
如何在 Windows 下的 Python 脚本中打开 unicode 命名文件(带有 空格) ?
文件名例如:Hello עולם.xls
对于非 unicode 无间距 xls 文件,os.system(filename) 效果很好。
对于非 unicode 间隔的 xls 文件,os.system('"'+filename+'"') 效果很好。
但是对于 unicode 空间 xls 文件...
os.system(filename) 和 subprocess.call(new_filename) 都给:
UnicodeEncodeError: 'ascii' 编解码器 无法在位置编码字符 12-13:序数不在范围内(128)
os.system(new_filename.encode('UTF-8')) 给出:
'Hello' 未被识别为 内部或外部命令,可操作 程序或批处理文件。
subprocess.call(new_filename.encode('UTF-8')) 给出:
WindowsError: [错误 2] 系统找不到指定的文件
【问题讨论】:
标签: python windows unicode subprocess os.system