Python Unicode: Difference between revisions

From OLPC
Jump to navigation Jump to search
No edit summary
m (Reverted edits by 60.27.15.11 (Talk); changed back to last version by Xavi)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Translations}}
Python has good [[unicode]] support, but it is not necessarily ''easy'' to use. Some things to note:
Python has good [[unicode]] support, but it is not necessarily ''easy'' to use. Some things to note:



Latest revision as of 13:10, 5 June 2007

  english | português | español HowTo [ID# 41190]  +/-  

Python has good unicode support, but it is not necessarily easy to use. Some things to note:

  • You must test your application with real Unicode (not ASCII-encodable) text. You can miss lots of bugs if you just use normal ASCII text (i.e., a-z, no accents).
  • You should be careful not to confuse 8-bit strings (that contain binary data and are of type "str"), and text (that contains unicode data and is of type "unicode"). It's easy to substitute one for the other, until you use non-ASCII text, then you'll get a UnicodeEncode/DecodeError.
  • The codecs module has some helpers for reading unicode from files.
  • You can't generally write unicode to a file or the console without setting up something with codecs or another wrapper.

Resources

Some resources to learn about Unicode: