【问题标题】:how can i change python console encoding MAC OSX我如何更改 python 控制台编码 MAC OSX
【发布时间】: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


    【解决方案1】:

    找到, 我的问题出在 python.sublime-build 文件中

    这个文件没有“env”行

    {
    "cmd": ["python3", "-u", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python",
    "encoding": "utf-8",
    "env": {"LANG": "fr_FR.UTF-8"}
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-18
      • 2011-03-14
      • 1970-01-01
      相关资源
      最近更新 更多