【发布时间】:2013-10-04 09:19:48
【问题描述】:
有没有办法在 Python 中将表示 Unicode 代码点的 int 转换为 Unicode 字符(字符串),其中相同的转换代码可以在 Python3+ 和 Python 2.7 中运行。
生成的字符串是 Unicode 字符串,可以是 Py3 中的纯字符串,也可以是 pre Py3 中的“from __future__ import unicode_literals”。
所以我们想要:
i = 404
c = chr_or_unichr (i) # this code is identical for different Python versions
>>> c
'Ɣ'
【问题讨论】:
标签: python string unicode int backwards-compatibility