Per 关于标识符的文档 https://docs.python.org/3/reference/lexical_analysis.html#identifiers:
解析时所有标识符都转换为标准形式NFKC;
标识符的比较基于NFKC。
您可以看到 U+03C4 是正确的结果unicodedata https://docs.python.org/3/library/unicodedata.html:
>>> import unicodedata
>>> unicodedata.normalize('NFKC', '????')
'τ'
然而,这种转换doesn't适用于字符串文字,就像您用作字典键的字符串文字一样,因此它会在字典中查找未转换的字符仅包含转换后的字符.
self.???? = 5 # implicitly converted to "self.τ = 5"
a.???? # implicitly converted to "a.τ"
d['????'] # not converted
您可以看到类似的问题,例如与使用的字符串文字getattr
:
>>> getattr(a, '????')
Traceback (most recent call last):
File "python", line 1, in <module>
AttributeError: 'Base' object has no attribute '????'
>>> getattr(a, unicodedata.normalize('NFKD', '????'))
5