TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Making Sense of Python Unicode

26 pointsby leecho0about 15 years ago

4 comments

jmillikinabout 15 years ago
"But UTF-8 has a dark side, a single character can take up anywhere between one to six bytes to represent in binary."<p>What? No! UTF-8 takes, <i>at most</i>, 4 bytes per code point.<p>"But UTF-8 isn't very efficient at storing Asian symbols, taking a whole three bytes. The eastern masses revolted at the prospect of having to buy bigger hard drives and made their own encodings."<p>Many asian users object to UTF-8/Unicode because of the Han Unification, and because many characters supported in other character sets are not present in Unicode. Size of the binary encoding has nothing to do with it -- in fact, most east-asian characters take 4 bytes in UTF-16.<p>"American programmers: In your day to day grind, it's superfluous to put a 'u' in front of every single string."<p>American programmers <i>who aren't morons</i>: Use 'u' or the first time somebody tries to run an accent through your code, it'll come out looking like line noise.
评论 #1341075 未加载
评论 #1341089 未加载
qwabout 15 years ago
<p><pre><code> Lobstertech wrote: &#62; American programmers: In your day to day grind, &#62; it's superfluous to put a 'u' in front of every single &#62; string."* Good idea, who cares about internationalization? You can always just pay someone in India to go over all of your code the day you notice the rest of the world Regards, European developer (... who doesn't want more competition)</code></pre>
s-phi-nlabout 15 years ago
A good tutorial on Python Unicode is <a href="http://diveintopython3.org/strings.html" rel="nofollow">http://diveintopython3.org/strings.html</a>. It's also my favorite explanation of Unicode in general.
leecho0about 15 years ago
bonus tip:<p>don't forget to add:<p><pre><code> # -*- coding: utf-8 -*- </code></pre> also, if you're using vim, make sure your encoding as well as your fileencoding are correct (they're different):<p><pre><code> set encoding=utf-8 set fileencoding=utf-8</code></pre>
评论 #1341330 未加载