[Python-3000] Weird error message from bytes type

Thomas Wouters thomas at python.org
Mon Feb 26 00:35:19 CET 2007

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 <nas at arctrix.com> 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')
> _______________________________________________
> Python-3000 mailing list
> Python-3000 at python.org
> http://mail.python.org/mailman/listinfo/python-3000
> Unsubscribe:
> http://mail.python.org/mailman/options/python-3000/thomas%40python.org

Thomas Wouters <thomas at python.org>

Hi! I'm a .signature virus! copy me into your .signature file to help me
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-3000/attachments/20070225/244ef688/attachment.htm 

More information about the Python-3000 mailing list