wtfpython
wtfpython copied to clipboard
Unicode variable name surprises
Utter madness.
>>> r = 1
>>> r
1
>>> 𝕣 = 2
>>> 𝕣
2
>>> r
2
I'm not sure why this is happening – not all non-ASCII characters in identifiers are translated into their closest ASCII match, but some are. This is in Python 3, of course, since Python 2 doesn't support these kinds of identifiers.
(It's entirely possible that this WTF is already in the document, I ctrlF'd for a few related terms but didn't find anything.)
where is the issue?
r
and 𝕣
, while sort of representing the same character, are not the same symbols, so them resolving to the same internal value was a surprise to me. Other – not-fundamentally-different – combinations such as R
and r
or A
and Å
don't exhibit this behavior.