[issue3532] bytes.tohex method

Matt Giuca report at bugs.python.org
Sat Aug 9 20:26:19 CEST 2008


Matt Giuca <matt.giuca at gmail.com> added the comment:

> I recommend to use binascii.hexlify.

Ah, see I did not know about this! Thanks for pointing it out.

* However, it is *very* obscure. I've been using Python for a year and I
didn't know about it.
* And, it requires importing binascii.
* And, it results in a bytes object, not a str. That's weird. (Perhaps
it would be good idea to change the functions in the binascii module to
output strings instead of bytes? Ostensibly it looks like this module
hasn't undergone py3kification).

Would it hurt to have the tohex method of the bytes object to perform
this task as well? It would be much nicer to use since it's a method of
the object rather than having to find out about and import and use some
function.

Also why have a bytes.fromhex method when you could use binascii.unhexlify?

(If it's better from a code standpoint, you could replace the code I
wrote with a call to binascii.unhexlify).

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3532>
_______________________________________


More information about the Python-bugs-list mailing list