Python tip: name your unicode characters
I got this tip from Trey Hunner’s newsletter. I would highly suggest signing up to his newsletter and looking at Python Morsels. If you use unicode in your code, create a variable instead of trying to use numerical codes:
| |
Instead of this:
| |
Explicitly name Unicode characters
That’s why I prefer to use \N{...} to reference Unicode characters by their name:
| |
That makes it much easier for me to guess what that character actually represents:
| |
It works for all Unicode characters, including multi-word names:
| |
How to find a character’s name
Don’t know the name of a Unicode character? Use unicodedata.name to look it up:
| |
You can also do a visual search on utf8.xyz (which Seth Larson started and I now own). Both searching by name (e.g. utf8.xyz/sparkles) or by the character itself (e.g. https://utf8.xyz/—) works.