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


Groups > comp.lang.python > #5605

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; 'way:': 0.05; 'bytes.': 0.07; 'type,': 0.07; 'python': 0.07; '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; 'wrote:': 0.14; 'curiosity,': 0.16; 'feature?': 0.16; 'furman': 0.16; 'immutable': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'charset:iso-8859-7': 0.16; 'traceback': 0.16; '(most': 0.16; 'bytes': 0.19; 'cc:2**0': 0.20; 'header:In-Reply-To:1': 0.22; 'cc:addr:python-list': 0.22; 'example.': 0.23; 'integer': 0.23; 'last):': 0.23; 'null': 0.23; 'way?': 0.23; 'example': 0.24; 'later': 0.26; 'object': 0.27; 'skip:b 20': 0.27; "doesn't": 0.28; 'list': 0.30; 'cc:addr:python.org': 0.31; 'do.': 0.31; 'typeerror:': 0.31; 'does': 0.31; 'anyone': 0.31; 'actually': 0.34; 'file': 0.35; 'header:User-Agent:1': 0.35; '"",': 0.35; 'assignment': 0.35; 'skip:. 10': 0.36; 'element': 0.38; 'so,': 0.38; 'question,': 0.39; 'though,': 0.39; 'would': 0.40; 'header:Received:5': 0.40; 'skip:h 20': 0.60; 'received:hostgator.com': 0.64; 'received:websitewelcome.com': 0.71; 'received:69.93': 0.91; 'received:gateway15.websitewelcome.com': 0.91
Date Tue, 17 May 2011 13:20:45 -0700
From Ethan Furman <ethan@stoneleaf.us>
User-Agent Thunderbird 1.5.0.10 (Windows/20070221)
MIME-Version 1.0
To Felipe Bastos Nunes <felipe.bastosn@gmail.com>
Subject Re: Python 3.x and bytes
References <4DD2C2A5.3080403@stoneleaf.us> <BANLkTimvzZeN5dmm2xHP5xV8Kpw2Nb9kuQ@mail.gmail.com>
In-Reply-To <BANLkTimvzZeN5dmm2xHP5xV8Kpw2Nb9kuQ@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-7; 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]:2902
X-Source-Auth ethan+stoneleaf.us
X-Email-Count 1
X-Source-Cap dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ==
Cc python-list <python-list@python.org>
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.1705.1305662916.9059.python-list@python.org> (permalink)
Lines 43
NNTP-Posting-Host 82.94.164.166
X-Trace 1305662917 news.xs4all.nl 49046 [::ffff:82.94.164.166]:43162
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:5605

Show key headers only | View raw


Felipe Bastos Nunes wrote:
> 2011/5/17 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
>> 
>> --> huh[3] = 9
>> Traceback (most recent call last):
>>  File "<stdin>", line 1, in <module>
>> TypeError: 'bytes' object does not support item assignment
>> 
>> 
>> So, out of curiosity, does anyone actually use this, um, feature?
 >
> They accept .replace(b"00", b"12") for example.

So they do.  Although that particular example doesn't work since b'0' is 
the integer 48...

--> huh.replace(b'00',b'12')
b'\x00\x00\x00\x00\x00'


The big question, though, is would you do it this way:

some_var = bytes(23).replace(b'\x00', b'a')

or this way?

some_var = bytes(b'a' * 23)

~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:20 -0700

csiph-web