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


Groups > comp.lang.python > #38505

Re: python3 binascii.hexlify ...

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'string.': 0.04; '"""': 0.05; 'binary': 0.05; 'subject:skip:b 10': 0.07; 'python': 0.09; '"""return': 0.09; 'bytes,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'sentence': 0.09; 'resulting': 0.13; 'hex': 0.16; 'hexadecimal': 0.16; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; 'simpson': 0.16; 'subject:python3': 0.16; 'wrote:': 0.17; 'byte': 0.17; 'bytes': 0.17; 'fixed.': 0.17; '>>>': 0.18; 'import': 0.21; 'converted': 0.22; 'seems': 0.23; 'header:User-Agent:1': 0.26; 'header:X -Complaints-To:1': 0.28; 'str': 0.29; '"the': 0.29; 'function': 0.30; 'url:python': 0.32; 'to:addr:python-list': 0.33; 'likely': 0.33; 'skip:b 20': 0.34; 'clear': 0.35; 'received:org': 0.36; 'url:org': 0.36; 'data.': 0.36; 'url:library': 0.36; 'should': 0.36; 'enough': 0.36; 'operating': 0.36; 'keeps': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'url:docs': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'easy': 0.60; 'here:': 0.62; 'subject:...': 0.63; '8bit%:21': 0.69; 'subject: ...': 0.84; 'str.': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: python3 binascii.hexlify ...
Date Sat, 09 Feb 2013 12:10:36 +0100
Organization None
References <20130209104433.GA13443@cskk.homeip.net>
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding 8Bit
X-Gmane-NNTP-Posting-Host p5084bc5c.dip.t-dialin.net
User-Agent KNode/4.7.3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1538.1360408239.2939.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1360408239 news.xs4all.nl 6840 [2001:888:2000:d::a6]:59654
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:38505

Show key headers only | 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