Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
打印字符串中字符的unicode数(Python)_Python_Python 2.7_Unicode - Fatal编程技术网

打印字符串中字符的unicode数(Python)

打印字符串中字符的unicode数(Python),python,python-2.7,unicode,Python,Python 2.7,Unicode,这应该很简单,但我无法破解 我在u'\u0600'-u'\u06FF'和u'\uFB50'-u'\uFEFF'之间有一个阿拉伯符号串。例如 如何打印每个字符的unicode编号?我正在使用Python 2.7 类似于以下内容的内容告诉我,不支持对Unicode进行解码: for c in example_string: print unicode(c,'utf-8') 您可以使用ord()函数 for c in example_string: print(ord(c), he

这应该很简单,但我无法破解

我在
u'\u0600'
-
u'\u06FF'
u'\uFB50'
-
u'\uFEFF'
之间有一个阿拉伯符号串。例如

如何打印每个字符的unicode编号?我正在使用Python 2.7


类似于以下内容的内容告诉我,不支持对Unicode进行解码

for c in example_string:
    print unicode(c,'utf-8')
您可以使用
ord()
函数

for c in example_string:
    print(ord(c), hex(ord(c)), c.encode('utf-8'))
将为您提供此字符的十进制、十六进制代码点以及UTF-8编码,如下所示:

(1594, '0x63a', '\xd8\xba')
(1610, '0x64a', '\xd9\x8a')
(1606, '0x646', '\xd9\x86')
(1610, '0x64a', '\xd9\x8a')
(1575, '0x627', '\xd8\xa7')
(32, '0x20', ' ')
  :
  :

在一篇评论中,您说“
\u06FF
是我试图打印的内容”-这也可以使用Python的
repr
函数来完成,尽管您似乎对hex(ord(c))非常满意。不过,对于正在寻找查找unicode字符ascii表示形式的人来说,这可能很有用

example_string = u'\u063a\u064a\u0646\u064a'

for c in example_string:
    print repr(c), c
输出

u'\u063a' غ
u'\u064a' ي
u'\u0646' ن
u'\u064a' ي
如果您想去掉Python unicode文本部分,您可以非常简单地这样做

for c in example_string:
    print repr(c)[2:-1], c
获取输出

\u063a غ
\u064a ي
\u0646 ن
\u064a ي

ord(u'\u06FF')
?可能重复@cᴏʟᴅsᴘᴇᴇᴅ: 别误会,我想打印的是
\u06FF
。您想要类似Python的字符串表示形式吗?