This question already has an answer here:
I have learnt from PEP 3131 that non-ASCII identifiers were supported in Python, though it's not considered best practice.
However, I get this strange behaviour, where my đ
identifier (U+1D70F) seems to be automatically converted to Ï
(U+03C4).
class Base(object):
def __init__(self):
self.đ = 5 # defined with U+1D70F
a = Base()
print(a.đ) # 5 # (U+1D70F)
print(a.Ï) # 5 as well # (U+03C4) ? another way to access it?
d = a.__dict__ # {'Ï': 5} # (U+03C4) ? seems converted
print(d['Ï']) # 5 # (U+03C4) ? consistent with the conversion
print(d['đ']) # KeyError: 'đ' # (U+1D70F) ?! unexpected!
Is that expected behaviour? Why does this silent conversion occur? Does it have anything to see with NFKC normalization? I thought this was only for canonically ordering Unicode character sequences...
Aucun commentaire:
Enregistrer un commentaire