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


Groups > comp.lang.python > #5591 > unrolled thread

Python 3.x and bytes

Started byEthan Furman <ethan@stoneleaf.us>
First post2011-05-17 11:47 -0700
Last post2011-05-17 11:47 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

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

#5591 — Python 3.x and bytes

FromEthan Furman <ethan@stoneleaf.us>
Date2011-05-17 11:47 -0700
SubjectPython 3.x and bytes
Message-ID<mailman.1691.1305657292.9059.python-list@python.org>
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?

~Ethan~

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web