[Python-Dev] Reintroduce or drop completly hex, bz2, rot13, ... codecs

Antoine Pitrou solipsis at pitrou.net
Wed Jun 9 21:56:59 CEST 2010


On Wed, 09 Jun 2010 15:45:55 -0400
Terry Reedy <tjreedy at udel.edu> wrote:
> On 6/9/2010 8:17 AM, Antoine Pitrou wrote:
> > On Wed, 9 Jun 2010 13:57:05 +0200
> > Dirkjan Ochtman<dirkjan at ochtman.nl>  wrote:
> >> On Wed, Jun 9, 2010 at 13:40, Antoine Pitrou<solipsis at pitrou.net>  wrote:
> >>> No, I don't think so. If I'm using hex "encoding", it's because I want
> >>> to see a text representation of some arbitrary bytestring (in order to
> >>> display it inside another piece of text, for example).
> >>> In other words, the purpose of hex is precisely to give a textual
> >>> display of non-textual data.
> >>
> >> Or I want to encode binary data in a non-binary-safe protocol, in
> >> which case I probably want bytes.
> >
> > In this case you would probably choose a more space-efficient
> > representation, such as base64 or base85.
> 
> Unless the receiver expects hex.

In which cases is this true? Hex is rarely used for ASCII-encoding of
binary data, precisely because its efficiency is poor.

> Please, hextext = str(somebytes.tranform('hex')) is quite easy and 
> explicit and will work for any bytes to ascii-subset transform, not just 
> 'hex'.

It will give you the str representation of a bytes object, which is not
what you want.
Of course, hextext = somebytes.tranform('hex').decode('ascii') is not
very hard either. But I disagree with the overall idea that bytes is
the good output type for hex encoding.

Regards

Antoine.




More information about the Python-Dev mailing list