【发布时间】:2015-03-03 23:54:18
【问题描述】:
我在这个有趣的线程中尝试了所有方法 Changing default encoding of Python? 但没有什么对我有用。 我使用崇高的文字,当我尝试时:
import sys
print(sys.stdout.encoding)
输出是:US-ASCII
我有一个可以在 Windows 下完美运行的 python 脚本(输出为: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
>>>
一切都好。但是...
当我在 sublime text (osX) 中尝试同样的事情时,它不起作用
我总是有这个错误
unicodeencodeerror 'ascii' codec can't encode character '\u0300' blabla
或类似错误
'str object has no attrbute decode'
我真的不明白我的问题出在哪里
求你的帮助
【问题讨论】:
标签: python macos encoding sublimetext2