python3编辑器sublime text 2输出中文字符UnicodeEncodeError,,在python2.7下,
python3编辑器sublime text 2输出中文字符UnicodeEncodeError,,在python2.7下,
在python2.7下,我在一个文件中输入了点中文字符,然后保存为txt格式文件,之后读取输入至控制台没有报错。但是切换至python3.3下,读取同样一个文件,就报错,提示:
/Users/nintenace/Desktop/learn_python
Traceback (most recent call last):
File "/Users/nintenace/Desktop/learn_python/test.py", line 7, in
print(str)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)
[Finished in 0.0s with exit code 1]
代码如下:
with open('ttt.txt','r',encoding='utf-8') as ttt: str = ttt.readline() print(str)
很奇怪为什么会这样,我是在mac下操作的,望高手解答!
http://stackoverflow.com/a/15174760
Preferences -> Browse Packages -> Python -> Python.sublime-build
加上一句 env,比如这样:
{ "cmd": ["/usr/local/bin/python3.3", "-u", "$file"], "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.python", "env": {"LANG": "en_US.UTF-8"}}
注意 selector 最后的逗号!
编橙之家文章,
相关内容
- Python pylo文件发送怎么操作,pythonpylo文件发送,我在用
- python文档中源码看不懂求大神指导,python大神,在查看文
- Python MongoDB正则与模糊查询出错,pythonmongodb,使用正则表
- 大家聊聊都有什么学习python的好方法或是技巧分享下吧
- Python下列源码中单例模式怎么理解,python源码理解,de
- Python验证码生成哪个包或是方法最实用,python验证码
- 请问epoll不触发hup是什么问题,请问epoll触发hup,一个简
- 为什么msys生成exe后被python subprocess调用却没有得不到返
- Python bottle分页实现求指点,pythonbottle,第一次使用Bott
- Python爬虫实现网易博客发表评论思路大神指导下,pyt
评论关闭