[Tutor] Unicode (utf-16-le)

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Sun Aug 24 17:05:17 EDT 2003



On Sat, 23 Aug 2003, Derek at leder wrote:

> Does anyone know of a module for converting utf-16-le to ascii?
> before I write one.

Hi Derek,

Strings support other character sets through the 'encode()' and 'decode()'
methods.  For example:

###
>>> s = 'hello world'
>>> utf_txt = s.encode('utf-16')
>>> utf_txt
'\xff\xfeh\x00e\x00l\x00l\x00o\x00 \x00w\x00o\x00r\x00l\x00d\x00'
>>> utf_txt.decode('utf-16')
u'hello world'
###

Here's a partial list of the character encodings that Python supports:

    http://www.python.org/doc/lib/node126.html

According to that list, 'utf-16-le' is a codec that it can handle, so you
should be in good shape.  *grin*


Good luck to you!




More information about the Tutor mailing list