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


Groups > comp.lang.python > #5611

Re: Python 3.x and bytes

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ethan@stoneleaf.us>
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; 'subject:Python': 0.04; 'bytes.': 0.07; 'pep': 0.07; 'type,': 0.07; 'python': 0.07; '>>>>': 0.09; 'ex:': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'received:gator410.hostgator.com': 0.09; '~ethan~': 0.09; 'pm,': 0.11; 'message-----': 0.14; 'wrote:': 0.14; '-----begin': 0.16; 'documented.': 0.16; 'furman': 0.16; 'hash:': 0.16; 'immutable': 0.16; 'iterable,': 0.16; 'pgp': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'received:gateway01.websitewelcome.com': 0.16; 'richardson': 0.16; 'sha1': 0.16; 'bytes': 0.19; 'header:In-Reply-To:1': 0.22; 'so.': 0.22; 'integer': 0.23; 'null': 0.23; 'later': 0.26; 'skip:b 20': 0.27; 'pass': 0.27; 'signed': 0.27; 'looks': 0.28; 'list': 0.30; 'it.': 0.31; 'to:addr:python-list': 0.32; 'using': 0.34; 'actually': 0.34; 'header:User-Agent:1': 0.35; '101': 0.35; 'element': 0.38; 'to:addr:python.org': 0.39; 'would': 0.40; "it's": 0.40; 'header:Received:5': 0.40; 'received:hostgator.com': 0.64; 'received:websitewelcome.com': 0.71
Date Tue, 17 May 2011 13:55:36 -0700
From Ethan Furman <ethan@stoneleaf.us>
User-Agent Thunderbird 1.5.0.10 (Windows/20070221)
MIME-Version 1.0
To python-list@python.org
Subject Re: Python 3.x and bytes
References <4DD2C2A5.3080403@stoneleaf.us> <4DD2D175.30506@aim.com>
In-Reply-To <4DD2D175.30506@aim.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - gator410.hostgator.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - stoneleaf.us
X-Source
X-Source-Args
X-Source-Dir
X-Source-Sender mail.admailinc.com ([192.168.10.136]) [72.11.125.166]:3024
X-Source-Auth ethan+stoneleaf.us
X-Email-Count 3
X-Source-Cap dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ==
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
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.1711.1305665007.9059.python-list@python.org> (permalink)
Lines 44
NNTP-Posting-Host 82.94.164.166
X-Trace 1305665007 news.xs4all.nl 49048 [::ffff:82.94.164.166]:54300
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:5611

Show key headers only | View raw


Corey Richardson wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On 05/17/2011 02:47 PM, Ethan Furman wrote:
>> In Python 3 one can say
>>
>> --> huh = bytes(5)
>>
>> Since the bytes type is actually a list of integers, I would have 
>> expected this to have huh being a bytestring with one element -- the 
>> integer 5.  Actually, what you get is:
>>
>> --> huh
>> b'\x00\x00\x00\x00\x00'
>>
>> or five null bytes.  Note that this is an immutable type, so you cannot 
>> go in later and say
> 
> For the bytes to actually be a 'list of integers', you need to pass it
> an iterable, ex:
>>>> bytes([5, 6, 1, 3])
> b'\x05\x06\x01\x03'

Not so.

--> huh = b'abcedfg'
--> huh[3]
101

It's a list of int's.

> - From help(bytes):
>  |  bytes(iterable_of_ints) -> bytes
>  |  bytes(string, encoding[, errors]) -> bytes
>  |  bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer
>  |  bytes(memory_view) -> bytes
> 
> Looks like you're using the fourth when you want the first, possibly?

Nope.  Apparently, it's not well documented.  If you check PEP 358 
you'll find it.

~Ethan~

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


Thread

Re: Python 3.x and bytes Ethan Furman <ethan@stoneleaf.us> - 2011-05-17 13:55 -0700

csiph-web