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


Groups > comp.lang.python > #59756

Re: inconsistency in converting from/to hex

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'base64': 0.16; 'codecs': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'removed,': 0.16; '>>>': 0.22; 'import': 0.22; 'header:User- Agent:1': 0.23; 'least': 0.26; 'subject:/': 0.26; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; "skip:' 10": 0.31; "d'aprano": 0.31; 'steven': 0.31; 'subject:skip:i 10': 0.31; "they'll": 0.31; 'subject:from': 0.34; 'but': 0.35; 'two': 0.37; '8bit%:86': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'back': 0.62; 'received:46': 0.66; '3.4': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Serhiy Storchaka <storchaka@gmail.com>
Subject Re: inconsistency in converting from/to hex
Date Sun, 17 Nov 2013 18:22:50 +0200
References <mailman.2742.1384640221.18130.python-list@python.org> <528862b2$0$29975$c3e8da3$5496439d@news.astraweb.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host 46.211.126.150
User-Agent Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.1.0
In-Reply-To <528862b2$0$29975$c3e8da3$5496439d@news.astraweb.com>
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 <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2786.1384705376.18130.python-list@python.org> (permalink)
Lines 37
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1384705376 news.xs4all.nl 15986 [2001:888:2000:d::a6]:47803
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:59756

Show key headers only | View raw


17.11.13 08:31, Steven D'Aprano написав(ла):
> There's already at least two ways to do it in Python 2:
>
> py> import binascii
> py> binascii.hexlify('Python')
> '507974686f6e'
>
> py> import codecs
> py> codecs.encode('Python', 'hex')
> '507974686f6e'

Third:

 >>> import base64
 >>> base64.b16encode(b'Python')
b'507974686F6E'

Fourth:

 >>> '%0*x' % (2*len(b'Python'), int.from_bytes(b'Python', byteorder='big'))
b'507974686F6E'

Fifth:

 >>> ''.join('%02x' % b for b in b'Python')
b'507974686F6E'

> [Aside: in Python 3, the codecs where (mistakenly) removed, but they'll
> be added back in 3.4 or 3.5.]

Only renamed.

 >>> import codecs
 >>> codecs.encode(b'Python', 'hex_codec')
b'507974686f6e'

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


Thread

inconsistency in converting from/to hex Laszlo Nagy <gandalf@shopzeus.com> - 2013-11-16 23:16 +0100
  Re: inconsistency in converting from/to hex Ned Batchelder <ned@nedbatchelder.com> - 2013-11-16 15:35 -0800
  Re: inconsistency in converting from/to hex Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-17 06:31 +0000
    Re: inconsistency in converting from/to hex Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-17 12:38 +0000
    Re: inconsistency in converting from/to hex Serhiy Storchaka <storchaka@gmail.com> - 2013-11-17 18:22 +0200

csiph-web