Question about binary file reading
Benjamin Peterson
benjamin at python.org
Wed Mar 4 23:13:02 EST 2009
John Machin <sjmachin <at> lexicon.net> writes:
> On Mar 5, 12:13 pm, Benjamin Peterson <benja... at python.org> wrote:
> >
> > import binascii
> > print binascii.hexlify(some_bytes)
>
> AFAICT binascii.hexlify(some_bytes) gives the SAME result as
> some_bytes.encode("hex") for much more typing -- I see no
> "better"
> here.
So called encodings like "hex" and "rot13" are abuse of
encode() method. encode() should translate
between byte strings and unicode, not preform
transformations like that. This has been removed
in 3.x, so you should use binascii.
More information about the Python-list
mailing list