On 8/8/07, Thomas Heller <[EMAIL PROTECTED]> wrote: > OTOH, I'm a little bit confused about the bytes type. I think this behaviour > is a little bit confusing, but maybe that's just me: > > >>> b"abc"[:] > b'abc' > >>> b"abc"[:1] > b'a' > >>> b"abc"[1] > 98 > >>> b"abc"[1] = 42 > >>> b"abc"[1] = "f" > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > TypeError: 'str' object cannot be interpreted as an integer > >>> b"abc"[1] = b"f" > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > TypeError: 'bytes' object cannot be interpreted as an integer > >>> > > Especially confusing is that the repr of a bytes object looks like a string, > but bytes do not contain characters but integers instead.
I hope you can get used to it. This design is a bit of a compromise -- conceptually, bytes really contain small unsigned integers in [0, 256), but in order to be maximally useful, the bytes literal (and hence the bytes repr()) shows printable ASCII characters as themselves (controls and non-ASCII are shown as \xXX). This is more compact too. PBP! -- --Guido van Rossum (home page: http://www.python.org/~guido/) _______________________________________________ Python-3000 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com
