Namedtuples: TypeError: 'str' object is not callable

Gregory Ewing greg.ewing at canterbury.ac.nz
Sat Jan 7 04:12:49 EST 2017


Deborah Swanson wrote:
>   File "E:/Coding projects/Pycharm/Moving/moving_numberedtuples.py",
> line 139, in moving()
>     for lst in map(listings._make, csv.reader(open('E:\\Coding
> projects\\Pycharm\\Moving\\Moving 2017 in.csv',"r"))):
> TypeError: 'str' object is not callable

I know you've found the answer to this one, but as a general
tip, if you're getting an exception from a complicated line like
that, it can pay to break it down into simpler steps, then you
can see more clearly at what stage of the process the exception
is occurring. E.g.

   file = open('E:\\Coding projects\\Pycharm\\Moving\\Moving 2017 in.csv',"r")
   reader = csv.reader(file)
   rows = map(listings._make, reader)
   for lst in rows:
     ...

In this case the traceback would have pointed you to the third
line, telling you that it was something to do with the map()
call.

-- 
Greg



More information about the Python-list mailing list