Pragmatic Unicode, or, How do I stop the pain?
Why Hacker News recommends it
Commenters point to it as the clearest explanation of Python's bytes versus Unicode model and the Unicode sandwich, which finally makes the confusion click.
What it is
Ned Batchelder's PyCon 2012 talk gives a quick overview of what Unicode is, then focuses on what a Python programmer needs to handle text correctly. It presents the 'Unicode sandwich' strategy: decode bytes at input, work with Unicode internally, encode at output.
Recommended by 2 HN commenters across 2 different months, 2015 to 2019.
What Hacker News said
Strong rec jteppinette · 2019-05 · on ““Python's batteries are leaking””
You have to invest some time in understanding how strings (byte strings and unicode) work in Python. I put this off for way too long. After A TON OF PAIN I decided to put the time in to watch the talk "Pragmatic Unicode, or, How do I stop the pain?"[0] by Ned Batchelder and it all just clicked. Now, I make unicode sandwiches like a boss. [0] [this video]
Recommends ptx · 2015-01 · on “Why Perl Didn't Win”
From a quick skimming through the docs[0], Perl 5.8's Unicode support sounds a lot like Python 2's except that the default encoding is latin1 instead of ASCII - i.e. unlike the Python 3 way of explicitly decoding binary data into Unicode text at the point where it's read (where presumably the encoding of the data is known), it will defer the decoding until the data is used (at some completely unrelated point in the program) and decode it with some assumed globally agreed upon encoding. Since there is no globally agreed encoding (Windows even has different legacy encodings between Win32 and the command prompt!) this will appear to work as long as the data is ASCII but later, when you least ex
Cites ptx · 2015-03 · on “Learn Python the Hard Way”
Python 3 is useful for a beginner to start with because they don't have to learn the deprecated cruft that Python 2 preserves for compatibility. If they just learn the Python 3 way of doing things, it generally works in both 2 and 3. In his explanation of classes he has several paragraphs about old-style vs. new-style classes, ending it with: "Just completely ignore the idea of old style versus new style classes and assume that Python always requires (object) when you make a class. Save your brain power for something important." Python 3 only has new-style classes, so the entire explanation could have been left out, allowing the beginner to, as he recommends, focus on more interesting things
Cites thanksgiving · 2017-11 · on “Numpy: Plan for dropping Python 2.7 support”
I don't know the details (because I don't understand unicode) but I am not sure what you said is possible. But to me ASCII seems like a hindrance. ``` fmt.Println("Hello, 世界") ``` This line of go lang looks beautiful. I bet they never have to worry about bytes vs Unicode. Here is python... [this video] I'll add one more assertion to the list. People are born and people die. It is not fair for us to impose our mistakes and sins to the next generation. With that being said, my thought was simply all the scripts that are in python (even the simple build for Firefox was python 2 only last time I checked). The way forward for anyone new to python is for us to tell them: Python 2 doesn't matter. Don't