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


Groups > comp.lang.python > #5604

Re: Python 3.x and bytes

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <kb1pkl@aim.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; 'bytes.': 0.07; 'type,': 0.07; 'python': 0.07; 'ex:': 0.09; 'pm,': 0.11; '>>>': 0.12; 'message-----': 0.14; 'wrote:': 0.14; '(gnu/linux)': 0.16; '-----begin': 0.16; '-----end': 0.16; 'from:addr:kb1pkl': 0.16; 'from:name:corey richardson': 0.16; 'furman': 0.16; 'gnupg': 0.16; 'hash:': 0.16; 'immutable': 0.16; 'iterable,': 0.16; 'message-id:@aim.com': 0.16; 'pgp': 0.16; 'received:64.12.207.164': 0.16; 'received:imr-mb01.mx.aol.com': 0.16; 'richardson': 0.16; 'sha1': 0.16; 'url:enigmail': 0.16; 'url:mozdev': 0.16; 'bytes': 0.19; 'comment:': 0.19; 'header:In- Reply-To:1': 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; 'to:addr:python-list': 0.32; 'using': 0.34; 'received:192': 0.34; 'actually': 0.34; 'received:192.168.0': 0.35; 'header:User-Agent:1': 0.35; 'received:192.168': 0.37; 'element': 0.38; 'url:org': 0.38; 'version:': 0.39; 'to:addr:python.org': 0.39; 'would': 0.40; 'skip:d 60': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=mx.aol.com; s=20110426; t=1305661849; bh=NtLgwS2uoqHnPtj8P/Tq/uBRnrgeD7zRY4FlcbEgC9E=; h=Message-ID:Date:From:MIME-Version:To:Subject:Content-Type; b=jcQzkfalUvFw/seLkaeXemjkbL/lGvU2ICYyjAM3T/hyGViOiVwbGFfTEoY2qd24A V6KuRwj+/i6zayuxT83uIXnQSUDVYiw0UeJSljk0mHQ5sleag4wZdTyQOWfTWGs1OG vX5iN1Z8xhCC1+re3tK3vCw7wDzJtKR+U9m0V0lk=
Date Tue, 17 May 2011 15:50:13 -0400
From Corey Richardson <kb1pkl@aim.com>
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110505 Lightning/1.0b3pre 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>
X-Enigmail-Version 1.1.2
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
x-aol-global-disposition G
X-AOL-SCOLL-SCORE 0:2:460201696:93952408
X-AOL-SCOLL-URL_COUNT 0
x-aol-sid 3039ac1d33c14dd2d19863f2
X-AOL-IP 71.168.99.50
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.1703.1305661863.9059.python-list@python.org> (permalink)
Lines 45
NNTP-Posting-Host 82.94.164.166
X-Trace 1305661864 news.xs4all.nl 49046 [::ffff:82.94.164.166]:41433
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:5604

Show key headers only | View raw


-----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'

- 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?

- -- 
Corey Richardson
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJN0tF1AAoJEAFAbo/KNFvp41AH/1l2zR6XVOJ0xM7s2P+PDYZX
OAhmi19hFEP0zQoWiW3TiMEVPlaqgtipPCp1t+jTeNNN3F+H4NG2DHJJZ3dPDr2J
CpABQKyS4MJQTUxhCIlXqAaA2I1pejzAv6fwsF66/zPFmyaTAJLDP+3WMQvCUUoZ
5A3qHgHNp6vBHXd13RNdQStLeprfQptA+z6XdiJPos348ecRj/u9id7v28dwxxsm
d9WA6oYwJ+Y/NcG2OP0Flyp3Zc3hymVsv5vhmhG2+EiIrxMn95k8ImsKLEhvUW3a
72CxlE6EaOMD4MuWyeGMS33c0vHwtAvEIE7M56R2FAl8EsUFwP2swaij0tEiemg=
=8MRV
-----END PGP SIGNATURE-----

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


Thread

Re: Python 3.x and bytes Corey Richardson <kb1pkl@aim.com> - 2011-05-17 15:50 -0400

csiph-web