Bruce Bruce - 2 years ago 89
Python Question

TypeError: 'long' object is not callable

I have steam coming out of my head now but I can't figure out what is wrong with my code.
Here are the relevant lines:

outport = record_dict[id][hash_ % len(record_dict[id])]

Here is the error I get:

File "", line 459, in yyyyy
TypeError: 'long' object is not callable

Inside file pointed by fp:

Problem-<type 'list'>
Problem-[5, 6, 7, 8]

What is wrong with my code? How do I debug it?

Answer Source

did you create a variable named str or len anywhere? If so, that's your problem. (most likely, len since str was used earlier without any problem).

Python builtins are not reserved -- meaning that you are free to reassign them to any object that you want. It looks like you assigned len to a long integer which makes sense because len is a perfectly reasonable variable name in other languages.

The thing you should take away from this is to be careful not to "shadow" builtin functions by creating variables of the same name. It makes problems which can be hard to debug.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download