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


Groups > comp.lang.python > #38505 > unrolled thread

Re: python3 binascii.hexlify ...

Started byPeter Otten <__peter__@web.de>
First post2013-02-09 12:10 +0100
Last post2013-02-09 12:10 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#38505 — Re: python3 binascii.hexlify ...

FromPeter Otten <__peter__@web.de>
Date2013-02-09 12:10 +0100
SubjectRe: python3 binascii.hexlify ...
Message-ID<mailman.1538.1360408239.2939.python-list@python.org>
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()
'äöü'

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web