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


Groups > comp.lang.python > #46737

Re: Output from to_bytes

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ned@nedbatchelder.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'output': 0.05; 'bytes,': 0.09; 'literal': 0.09; 'output,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'character.': 0.16; 'escapes': 0.16; 'hex': 0.16; 'hexadecimal': 0.16; 'literal.': 0.16; 'notation': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'example': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'bytes': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'code:': 0.26; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'skip:p 30': 0.29; "doesn't": 0.30; 'characters': 0.30; 'prints': 0.31; 'subject:from': 0.34; 'could': 0.34; 'module.': 0.36; 'should': 0.36; 'pm,': 0.38; 'how': 0.40; '2nd': 0.60; 'yourself,': 0.95
Date Sun, 02 Jun 2013 18:18:07 -0400
From Ned Batchelder <ned@nedbatchelder.com>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6
MIME-Version 1.0
To Mok-Kong Shen <mok-kong.shen@t-online.de>
Subject Re: Output from to_bytes
References <knstkh$74a$1@news.albasani.net> <ko2irn$9oh$1@reader1.panix.com> <kog58p$nmi$1@news.albasani.net>
In-Reply-To <kog58p$nmi$1@news.albasani.net>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Cc python-list@python.org
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.2565.1370211491.3114.python-list@python.org> (permalink)
Lines 36
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1370211491 news.xs4all.nl 15909 [2001:888:2000:d::a6]:38034
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:46737

Show key headers only | View raw


On 6/2/2013 3:09 PM, Mok-Kong Shen wrote:
> Am 28.05.2013 17:35, schrieb Grant Edwards:
>> On 2013-05-26, Mok-Kong Shen <mok-kong.shen@t-online.de> wrote:
>>> I don't understand why with the code:
>>>
>>>      for k in range(8,12,1):
>>>        print(k.to_bytes(2,byteorder='big'))
>>>
>>> one gets the following output:
>>>
>>>      b'\x00\x08'
>>>      b'\x00\t'
>>>      b'\x00\n'
>>>      b'\x00\x0b'
>>>
>>> I mean the 2nd and 3rd should be b'\x00\x09' and b'x00\x0a'.
>>> Anyway, how could I get the output in the forms I want?
>>
>> Well, it would help if you told us what output form you want.
>
> As I stated, I like the 2nd and 3rd be b'\x00\x09' and b'\x00\x0a'
> respectively. This is what would expeacted to be in a hexadecimal
> notation IMHO in other PLs.
>

When you print bytes, Python doesn't use "hexadecimal notation."  It 
prints a Python bytes literal.  That literal will use printable 
characters like 'Q', or hex escapes like '\x00', or other escapes like 
'\n', depending on the character.   If you want hex output, you have to 
create it yourself, for example with the binascii module.

--Ned.

> M. K. Shen
>

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


Thread

Output from to_bytes Mok-Kong Shen <mok-kong.shen@t-online.de> - 2013-05-26 14:02 +0200
  Re: Output from to_bytes Chris Angelico <rosuav@gmail.com> - 2013-05-26 23:26 +1000
  Re: Output from to_bytes Terry Jan Reedy <tjreedy@udel.edu> - 2013-05-26 16:45 -0400
  Re: Output from to_bytes Grant Edwards <invalid@invalid.invalid> - 2013-05-28 15:35 +0000
    Re: Output from to_bytes Mok-Kong Shen <mok-kong.shen@t-online.de> - 2013-06-02 21:09 +0200
      Re: Output from to_bytes Ned Batchelder <ned@nedbatchelder.com> - 2013-06-02 18:18 -0400

csiph-web