gett error message: "TypeError: 'int' object is not callable"
davea at ieee.org
Thu Jul 9 16:52:14 CEST 2009
> I've seen a lot of posts on this problem, but none seems to help.
> Here is the code:
> file = open(prefix1)
> text = file.readlines()
> len = len(text)
> fields = text.split()
> num_rows = int(fields)
> num_cols = int(fields)
> U1_matrix = 
> print fields
> print repr(fields)
> print len(fields)
> for line in text[2: num_rows+2]:
> fields = line.split()
> # print "fields", fields, line
> for i in range(len(fields)):
> fields[i] = float(fields[i])
> prefix is a space/line delimited ascii file that represents a 2D
> matrix. i'm trying to read in 2 matrices from different files, strip
> away the header stuff and then take the dot product of the 2
> matrices. any help is much appreciated.
You have at least two problems with that code, one of which is causing
Both 'file' and 'len' are defined in the standard library, and shouldn't
be redefined in your code. And your problem is that after you redefined
'len', you then tried to use it in its original meaning.
Rename those two and you'll get further.
And it would have saved lots of time for lots of people if you included
sample data and the actual error message, marking where in your code it
occurs. Once you know it's complaining about the len() call, it's not
too hard to figure out that the problem was you rebound the len
attribute from a function to an integer.
Traceback (most recent call last):
File "M:\Programming\Python\sources\dummy\echo2.py", line 21, in <module>
TypeError: 'int' object is not callable
More information about the Python-list