是否可以表示非ASCII字符? [英] Is it possible to represent non-ASCII characters?

查看:129
本文介绍了是否可以表示非ASCII字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道在打印语句中在python上表示非ASCII符号的方法,例如此符号ŷ"的方法吗?

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

推荐答案

您应使用UTF-8编码系统.

You should use the UTF-8 coding system.

Python文件的第一行应为:

The first line of your Python file should be:

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

如果这不起作用,请尝试使用unicode(string)来包装您的字符串.

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

print unicode("éáóý");

如果这仍然行不通,请尝试在所有代码之前但在#--编码之后添加这些行:utf-8--

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")

最后,请确保将文件另存为UTF-8,并且您的控制台支持Unicode字符.

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

这篇关于是否可以表示非ASCII字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆