T
tleeuwenburg
It started with this error message... "TypeError: object cannot be
used as an index"
foo = {}
someObject = someClass()
foo[someObject] = "hello"
Obviously, there are some known reasons why objects may not be
indexes, such as if they are not hashable (as in the case of lists).
However, I'm not getting that error message. I tested this out with
some minimal Python code, and the error did not occur. It only occurs
in my big codebase, not in a neat minimal example using a very small
class.
The type of this object is listed as 'instance'. My interpreter is
2.5.1
So I tried looking for more information inside types, and found
types.InstanceType.
Running help(types.InstanceType) gave me:hello
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/python-2.5.1/lib/python2.5/site.py", line 345, in
__call__
import pydoc
File "/usr/local/python-2.5.1/lib/python2.5/pydoc.py", line 56, in
<module>
from repr import Repr
ImportError: cannot import name Repr
There is a good chance that this object is build from C code,
instantiated through Swig. I'll have to do a bit more work to trace
back where the problem object is being created...
What, exactly, needs to be in place for an object to be a valid
dictionary key?
used as an index"
foo = {}
someObject = someClass()
foo[someObject] = "hello"
Obviously, there are some known reasons why objects may not be
indexes, such as if they are not hashable (as in the case of lists).
However, I'm not getting that error message. I tested this out with
some minimal Python code, and the error did not occur. It only occurs
in my big codebase, not in a neat minimal example using a very small
class.
The type of this object is listed as 'instance'. My interpreter is
2.5.1
So I tried looking for more information inside types, and found
types.InstanceType.
Running help(types.InstanceType) gave me:hello
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/python-2.5.1/lib/python2.5/site.py", line 345, in
__call__
import pydoc
File "/usr/local/python-2.5.1/lib/python2.5/pydoc.py", line 56, in
<module>
from repr import Repr
ImportError: cannot import name Repr
There is a good chance that this object is build from C code,
instantiated through Swig. I'll have to do a bit more work to trace
back where the problem object is being created...
What, exactly, needs to be in place for an object to be a valid
dictionary key?