[Python-Dev] bytes.from_hex()
Greg Ewing
greg.ewing at canterbury.ac.nz
Fri Mar 3 00:39:16 CET 2006
Ron Adam wrote:
> This uses syntax to determine the direction of encoding. It would be
> easier and clearer to just require two arguments or a tuple.
>
> u = unicode(b, 'encode', 'base64')
> b = bytes(u, 'decode', 'base64')
The point of the exercise was to avoid using the terms
'encode' and 'decode' entirely, since some people claim
to be confused by them.
While I succeeded in that, I concede that the result
isn't particularly intuitive and is arguably even more
confusing.
If we're going to continue to use 'encode' and 'decode',
why not just make them functions:
b = encode(u, 'utf-8')
u = decode(b, 'utf-8')
In the case of Unicode encodings, if you get them
backwards you'll get a type error.
The advantage of using functions over methods or
constructor arguments is that they can be applied
uniformly to any input and output types.
--
Greg
More information about the Python-Dev
mailing list