Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #5602
| Date | 2011-05-17 20:39 +0100 |
|---|---|
| From | MRAB <python@mrabarnett.plus.com> |
| Subject | Re: Python 3.x and bytes |
| References | <4DD2C2A5.3080403@stoneleaf.us> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1701.1305661148.9059.python-list@python.org> (permalink) |
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
Re: Python 3.x and bytes MRAB <python@mrabarnett.plus.com> - 2011-05-17 20:39 +0100
csiph-web