[Python-Dev] bytes.from_hex()

Delaney, Timothy (Tim) tdelaney at avaya.com
Thu Mar 2 22:48:31 CET 2006


Just van Rossum wrote:

> My preference for bytes -> unicode -> bytes API would be this:
> 
>     u = unicode(b, "utf8")  # just like we have now
>     b = u.tobytes("utf8")   # like u.encode(), but being explicit
>                             # about the resulting type

+1 - I was going to write exactly the same thing. The `bytes` type
shouldn't know anything about unicode - conversions between bytes and
unicode is entirely the responsibility of the unicode type.

Alternatively, rather than as part of the constructor (though that seems
the obvious place) some people may prefer a classmethod:

    unicode.frombytes(cls, encoding)

It gives a nice symmetry.

Tim Delaney


More information about the Python-Dev mailing list