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


Groups > comp.lang.python > #5602

Re: Python 3.x and bytes

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
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; 'suppose': 0.05; 'bytes.': 0.07; 'feature.': 0.07; 'type,': 0.07; 'python': 0.07; 'from:addr:python': 0.09; 'wrote:': 0.14; 'curiosity,': 0.16; 'feature?': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'furman': 0.16; 'immutable': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'reply- to:addr:python-list': 0.16; 'traceback': 0.16; '(most': 0.16; 'bytes': 0.19; 'header:In-Reply-To:1': 0.22; 'producing': 0.22; 'integer': 0.23; 'last):': 0.23; 'null': 0.23; 'example': 0.24; 'received:84': 0.25; 'accepting': 0.26; 'later': 0.26; 'object': 0.27; 'skip:b 20': 0.27; "doesn't": 0.28; 'list': 0.30; 'seem': 0.30; 'btw,': 0.31; 'typeerror:': 0.31; 'does': 0.31; 'anyone': 0.31; 'to:addr:python-list': 0.32; "i've": 0.33; 'actually': 0.34; 'file': 0.35; 'header:User-Agent:1': 0.35; '"",': 0.35; 'assignment': 0.35; 'reply-to:addr:python.org': 0.35; 'element': 0.38; 'but': 0.38; 'so,': 0.38; 'used': 0.38; 'it!': 0.39; 'lets': 0.39; 'to:addr:python.org': 0.39; 'would': 0.40; 'might': 0.40; 'high': 0.66; 'reply-to:no real name:2**0': 0.72; 'header:Reply- To:1': 0.72
X-IronPort-Anti-Spam-Filtered true
X-IronPort-Anti-Spam-Result AogIALDO0k3Unw4S/2dsb2JhbACYCI4Md8cnhhkElECKRw
Date Tue, 17 May 2011 20:39:12 +0100
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10
MIME-Version 1.0
To python-list@python.org
Subject Re: Python 3.x and bytes
References <4DD2C2A5.3080403@stoneleaf.us>
In-Reply-To <4DD2C2A5.3080403@stoneleaf.us>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To python-list@python.org
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.1701.1305661148.9059.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 82.94.164.166
X-Trace 1305661149 news.xs4all.nl 49180 [::ffff:82.94.164.166]:50361
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:5602

Show key headers only | View raw


On 17/05/2011 19:47, 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?
>
I suppose it follows the example of 'list' and 'tuple' in accepting an
iterable.

Producing a bytestring of zero bytes might have its uses, but because
Python lets me do coding at a high level (lists, dicts, etc), I've
never used that feature.

BTW, help(bytes) doesn't seem to mention it!

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


Thread

Re: Python 3.x and bytes MRAB <python@mrabarnett.plus.com> - 2011-05-17 20:39 +0100

csiph-web