Question about binary file reading

Tino Wildenhain tino at wildenhain.de
Thu Mar 5 02:30:20 EST 2009


Benjamin Peterson wrote:
> 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.

Thats actually not what I understand of the encoding/decoding
methods (which are very handy, beside the pure charset
conversions) that is, they translate between multiple (e.g.
1-n byte strings to a single byte encoding (for encode)
and the other way round for decode.

Charset mapping is surely the original purpose but I see no
reason why all the "pseudo" encodings are bad - since after
all they are encodings (base64, hex, ... even gzip)
what is missing at the moment would be urlencoding.

Cheers
Tino
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3241 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20090305/2ecbdbe9/attachment.bin>


More information about the Python-list mailing list