Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #38505

Re: python3 binascii.hexlify ...

From Peter Otten <__peter__@web.de>
Subject Re: python3 binascii.hexlify ...
Date 2013-02-09 12:10 +0100
Organization None
References <20130209104433.GA13443@cskk.homeip.net>
Newsgroups comp.lang.python
Message-ID <mailman.1538.1360408239.2939.python-list@python.org> (permalink)

Show all headers | View raw


Cameron Simpson wrote:

> This seems to return a bytes object in Python 3.3.0. I was expecting a
> string. The documentation here:
> 
>   http://docs.python.org/3/library/binascii.html#binascii.hexlify
> 
> also keeps me expecting a string. Am I missing something?

"""Return the hexadecimal representation of the binary data. Every byte of 
data is converted into the corresponding 2-digit hex representation.
"""

makes it pretty clear that the function is operating on bytes, not str.

The following sentence "The resulting string..." is likely a leftover from 
Python 2 and should be fixed.

If you need str instead of bytes it's easy enough to do the 
encoding/decoding yourself:

>>> import binascii as ba
>>> ba.hexlify("äöü".encode())
b'c3a4c3b6c3bc'
>>> ba.unhexlify(_).decode()
'äöü'

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: python3 binascii.hexlify ... Peter Otten <__peter__@web.de> - 2013-02-09 12:10 +0100

csiph-web