Dr. Dobb's Python-URL! - weekly Python news and links (Dec 30)

Max M maxm at mxm.dk
Wed Jan 5 11:09:32 CET 2005

Carl Banks wrote:

> Also, note that there are some encodings unrelated to Unicode.  For
> example, try this:
> . >>> "abcd".encode("base64")
> This is an encoding between two byte strings.

Yes. This can be especially nice when you need to use restricted charsets.

I needed to use unicode objects as Zope ids. But Zope only accepts a 
subset of ascii as ids.

So I used:

     hex_id = u'INBOX'.encode('utf-8').encode('hex')

And I can get the unicode representation back with:

     unicode_id = id.decode('hex').decode('utf-8')

Tn that case id.decode('hex') doesn't return a unicode, but a utf-8 
encoded string.


hilsen/regards Max M, Denmark

IT's Mad Science

More information about the Python-list mailing list