[Python-3000] Weird error message from bytes type
Delaney, Timothy (Tim)
tdelaney at avaya.com
Tue Feb 27 01:55:39 CET 2007
Greg Ewing wrote:
> Nick Coghlan wrote:
>> For example, simply
>> replacing 'index' with 'integer' could lead to a different kind of
>> confusion: TypeError: 'float' object cannot be interpreted as an
>> integer
>
> Maybe something like
>
> TypeError: 'float' object cannot be used as an integer in this
> context
Going back to the original proposal:
>>> x = b'a'
>>> x[0] = b'a'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'bytes' object cannot be used as an integer in this context
Not too bad. +1 as a default.
> Or maybe require the caller to pass in an error message
> format, or at least have a version of the call which
> allows that.
+1
>>> x = b'a'
>>> x[0] = b'a'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Cannot assign 'bytes' object to 'bytes' element
>>> x = b'a'
>>> x[0] = [1]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Cannot assign 'list' object to 'bytes' element
Tim Delaney
More information about the Python-3000
mailing list