我有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
在终端还可以。
任何人都知道为什么会这样吗?你能复制吗?还是只对我的设置有用?
更改:
print u'\u0410'
至:
print u'\u0410'.encode('utf-8')
这里发生的是vim在2>&1 | tee
(从shellpipe
设置中设置)之后make
(从makeprg
设置中)添加。因此,您的test.py
脚本实际上已被重定向。尝试运行$ test.py > /tmp/foo
,您将得到相同的错误。解决方案:将您的输出编码为合理的编码,例如utf-8
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句