我如何更改 python 控制台编码 MAC OSX
how can i change python console encoding MAC OSX
我在这个有趣的线程中尝试了所有方法
Changing default encoding of Python?
但对我没有任何用处。
我使用 sublime text,当我尝试时:
import sys
print(sys.stdout.encoding)
输出为:US-ASCII
我有一个 python 脚本可以在 Windows 下完美运行(输出为:utf-8)
但是在osx 10.10.2 上,我总是遇到问题
另一件事可能有助于回答,
当我在 python shell (osX) 中尝试此代码时:
>>> leString = '/Users/djex/Desktop/dosser\ é\ espace'
>>> type(leString)
<class 'str'>
>>> stringNew = leString.encode('utf-8')
>>> type(stringNew)
<class 'bytes'>
>>> print (stringNew)
b'/Users/djex/Desktop/dosser\ \xc3\xa9\ espace'
>>> print (stringNew.decode('utf-8'))
/Users/djex/Desktop/dosser\ é\ espace
>>>
全部是ok.but...
当我在 sublime text (osX) 中尝试同样的事情时,它不起作用
我总是有这个错误
unicodeencodeerror 'ascii' codec can't encode character '\u0300' blabla
或类似
的错误
'str object has no attrbute decode'
我不太明白我的问题出在哪里
谢谢你的帮助
找到,
我的问题在 python.sublime-build file
此文件没有 "env" 行
{
"cmd": ["python3", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"encoding": "utf-8",
"env": {"LANG": "fr_FR.UTF-8"}
}
我在这个有趣的线程中尝试了所有方法 Changing default encoding of Python? 但对我没有任何用处。 我使用 sublime text,当我尝试时:
import sys
print(sys.stdout.encoding)
输出为:US-ASCII
我有一个 python 脚本可以在 Windows 下完美运行(输出为:utf-8)
但是在osx 10.10.2 上,我总是遇到问题
另一件事可能有助于回答, 当我在 python shell (osX) 中尝试此代码时:
>>> leString = '/Users/djex/Desktop/dosser\ é\ espace'
>>> type(leString)
<class 'str'>
>>> stringNew = leString.encode('utf-8')
>>> type(stringNew)
<class 'bytes'>
>>> print (stringNew)
b'/Users/djex/Desktop/dosser\ \xc3\xa9\ espace'
>>> print (stringNew.decode('utf-8'))
/Users/djex/Desktop/dosser\ é\ espace
>>>
全部是ok.but...
当我在 sublime text (osX) 中尝试同样的事情时,它不起作用
我总是有这个错误
unicodeencodeerror 'ascii' codec can't encode character '\u0300' blabla
或类似
的错误'str object has no attrbute decode'
我不太明白我的问题出在哪里
谢谢你的帮助
找到, 我的问题在 python.sublime-build file
此文件没有 "env" 行
{
"cmd": ["python3", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"encoding": "utf-8",
"env": {"LANG": "fr_FR.UTF-8"}
}