相关疑难解决方法(0)

标识符规范化:为什么微标志转换为希腊字母mu?

我偶然发现了以下奇怪的情况:

>>> class Test:
        µ = 'foo'

>>> Test.µ
'foo'
>>> getattr(Test, 'µ')
Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    getattr(Test, 'µ')
AttributeError: type object 'Test' has no attribute 'µ'
>>> 'µ'.encode(), dir(Test)[-1].encode()
(b'\xc2\xb5', b'\xce\xbc')
Run Code Online (Sandbox Code Playgroud)

我输入的字符始终是键盘上的μ符号,但由于某种原因它会被转换.为什么会这样?

python unicode identifier python-3.x python-internals

25
推荐指数
1
解决办法
792
查看次数