【发布时间】:2014-03-16 20:25:24
【问题描述】:
我有文件test.py 的内容:
print u'\u0410'
和Makefile:
test:
python test.py
当我用 Vim :!python test.py 写代码时,我明白了
А
Press ENTER or type command to continue
但是当我写 :make test 我得到了
python test.py
Traceback (most recent call last):
File "test.py", line 1, in <module>
print u'\u0410'
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0410' in position 0: ordinal not in range(128)
make: *** [test] Error 1
Press ENTER or type command to continue
终端中的make test 没问题。
有人知道为什么会这样吗?你能重现吗?或者它只是我的设置?
【问题讨论】:
-
我可以复制它。我不知道为什么会这样。但它在 shell 中工作方式不同的原因是
:make test是通过 vim 的内部命令调用 make 。 (所以 vim 可能搞砸了)。这与在 shell 中运行 make 的:!make test不同。 (注意!)。好像和这个stackoverflow.com/questions/20923663/…一样的问题 -
在 makefile 中使用
PYTHONIOENCODING=utf-8 python test.py可以解决问题。这取自之前链接问题的答案。
标签: python vim encoding makefile