根据文档,在 Python 2.7.3 中,shlex 应该支持 UNICODE。但是,当运行下面的代码时,我得到:UnicodeEncodeError: 'ascii' codec can't encode characters in position 184-189: ordinal not in range(128)
难道我做错了什么?
import shlex
command_full = u'software.py -fileA="sequence.fasta" -fileB="新建文本文档.fasta.txt" -output_dir="..." -FORMtitle="tst"'
shlex.split(command_full)
确切的错误如下:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shlex.py", line 275, in split
lex = shlex(s, posix=posix)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shlex.py", line 25, in __init__
instream = StringIO(instream)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 44-49: ordinal not in range(128)
这是我的 mac 使用来自 macports 的 python 的输出。我在使用“本机”python 2.7.3 的 Ubuntu 机器上遇到了完全相同的错误。