Python Unicode: Difference between revisions

From OLPC
Jump to navigation Jump to search
m (links)
No edit summary
Line 6: Line 6:


* The [http://python.org/doc/current/lib/module-codecs.html codecs] module has some helpers for reading unicode from files.
* The [http://python.org/doc/current/lib/module-codecs.html 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==
==Resources==
Line 16: Line 18:
* [http://www.tutorialsall.com/PYTHON/ascii-latin/ ascii to latin1] (and back again). A thread about searching unicode text, so that for example a search for "televisao" matches "televisão"
* [http://www.tutorialsall.com/PYTHON/ascii-latin/ ascii to latin1] (and back again). A thread about searching unicode text, so that for example a search for "televisao" matches "televisão"
* [http://unicode.org/faq/normalization.html Normalization FAQ] (not Python-specific) -- a single unicode string can be encoded multiple ways via "surrogates". This introduces ambiguity. This talks about some of that.
* [http://unicode.org/faq/normalization.html Normalization FAQ] (not Python-specific) -- a single unicode string can be encoded multiple ways via "surrogates". This introduces ambiguity. This talks about some of that.
* [http://pylonshq.com/docs/0.9.4/internationalization.html The Pylons Internationalization document] has a lot of information that is generally applicable to Python.


[[Category:Developers]]
[[Category:Developers]]

Revision as of 03:57, 12 January 2007

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: