【发布时间】:2015-07-06 12:07:52
【问题描述】:
我偶然发现了http://mortoray.com/2013/11/27/the-string-type-is-broken/
令我恐惧的是......
print(len('noe\u0308l')) # returns 5 not 4
但是我发现 https://stackoverflow.com/a/14682498/1267259, Normalizing Unicode
from unicodedata import normalize
print(len(unicodedata.normalize('NFC','noe\u0308l'))) # returns 4
但是我该怎么处理薛定谔的猫呢?
print(len('????????')) # returns 4 not 2
(附带问题:在我的文本编辑器中,当我尝试保存时,我得到一个“utf-8 编解码器无法在位置 y 编码字符 x:不允许代理”但在命令提示符下我可以粘贴并运行带有这些字符的代码,我认为这是因为猫存在于不同的量子水平(SMP)上,但我该如何标准化它们?)
我还应该做些什么来确保所有字符都计为“1”?
【问题讨论】:
-
Python 3 的哪个特定版本? Unicode 处理发生了一两次变化。
-
我使用的是 python 3.4.0。
标签: python python-3.x unicode python-unicode unicode-normalization