Thomas is correct. You can only assign ints in range(256) to a single index. This would work:
x[:1] = b"a" The error comes from the call to PyNumber_AsSsize_t() in bytes_setitem(), which apparently looks for __index__ or the tp_index slot. --Guido On 2/25/07, Thomas Wouters <[EMAIL PROTECTED]> wrote: > > This is because a bytes object is not a sequence of bytes objects, like > strings. It's a sequence of small integer values, so you need to assign a > small integer value to it. You can assign b'a'[0] to it, or assign b'a' to > x[:1]. I guess we could specialcase length-1 bytes to make this work > 'naturally', but I'm not sure that's the right approach. Guido? > > > On 2/25/07, Neil Schemenauer <[EMAIL PROTECTED]> wrote: > > > > >>> x = b'a' > > >>> x[0] = b'a' > > Traceback (most recent call last): > > File "<stdin>", line 1, in <module> > > TypeError: 'bytes' object cannot be interpreted as an index > > > > Huh? 0 is not a 'bytes' object and I don't see how the RHS is being > > used as an index. Obviously I wanted something like: > > > > >>> x[0] = ord(b'a') -- --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
