[Python-3000] Bytes and unicode conversion in C extensions

Andrew McNamara andrewm at object-craft.com.au
Wed Jul 30 04:24:01 CEST 2008

>Another approach would be to add a new bsddb method to specify the
>default encoding to use to convert unicode->bytes, and to do the
>conversion internally when getting unicode data as a parameter. The
>issue here is that "u'hi' != b'hi'", so the translation must be done
>both when storing and when retrieving data.

What about a new keyword argument to the constructor, "encoding". If
specified, *only* accept unicode (and do the conversion internally). If
not specified, only accept bytes. That way, people dealing with "strings"
can set-and-forget, people doing hairy stuff can use bytes, and mistakes
instantly result in an exception.

Andrew McNamara, Senior Developer, Object Craft

More information about the Python-3000 mailing list