Strange problems with encoding

Michael Hudson mwh at python.net
Thu Nov 6 10:24:25 EST 2003


Rudy Schockaert <rudy.schockaert at pandoraSTOPSPAM.be> writes:

> > 
> >>>>u'ö'.encode('utf-8').encode('base64')
> > 'w7Y=\n'
> 
> This works indeed. And thanks to Joe Fromm's hint (site.py) I don't
> have to worry about it anymore.

Well, I'm from the setdefaultencoding-is-evil camp, but it sounds like
you're in a pretty icky situation.

> > What would you like to do with a character that isn't in latin-1?
> > 
> Actually, I don't care as long as the encode and decode on the same
> machine give me back the original value.

Huh?

> >>The reason I want to base64-encode these unicode strings is because I
> >>get those as input and want to store them in a MySQL database using
> >>SQLObject.
> > ! Why can't you just encode them as utf-8 strings?  (Or, thinking
> > about it, why doesn't SQLObject support unicode?)
> > 
> 
> The actual input strings don't really contain unicode text values, but
> rather binary values i get as result from calling win32.NetUserEnum.

Oh, so they're not really unicode strings at all?  Blech.  That's
really really nasty.  Binary data should really be represented as
(narrow) strings in Python.  Perhaps the utf-16-le codec would be the
most appropriate...

Cheers,
mwh

-- 
  Q: What are 1000 lawyers at the bottom of the ocean?
  A: A good start.
  (A lawyer told me this joke.)
                                  -- Michael Ströder, comp.lang.python




More information about the Python-list mailing list