Is it possible to represent non-ASCII characters?

痴心易碎 提交于 2019-12-25 03:59:09

问题


Does anyone know of a way to represent Non-ASCII symbols such as this symbol "ŷ" on python in a print statement?


回答1:


You should use the UTF-8 coding system.

The first line of your Python file should be:

# -*- coding: utf-8 -*-

If this doesn't work, try wrapping your string with unicode(string).

print unicode("éáóý");

If this still doesn't work, try adding these lines before all code but after # -- coding: utf-8 --

import sys
if not hasattr(sys, "setdefaultencoding"):
    reload(sys)
sys.setdefaultencoding("utf-8")

Finally, make sure that you are saving the file as UTF-8 and that your console supports unicode characters.



来源:https://stackoverflow.com/questions/24112984/is-it-possible-to-represent-non-ascii-characters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!