Namedtuples: TypeError: 'str' object is not callable

Deborah Swanson python at deborahswanson.net
Sat Jan 7 04:41:56 EST 2017


Gregory Ewing wrote, on January 07, 2017 1:13 AM
> 
> 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

Thanks Greg. I'm really kicking myself for seeing everything in that
statement except the 'map('! Not really sure why it was invisible to me,
but the mind is very devious (also a Terrible Thing to Taste, according
to Ministry).

But your method gives a systematic way to break things down and look at
them one by one. It can be really dismaying to have a complex statement
like this one, that you copied from an example, and have it spit out
error after error no matter what you try.  Having a systematic method of
approach is quite probably guaranteed to succeed.

(I'll bet you can guess why I'm taking on numberedtuples. Hope to have
the rewritten code using them soon, and the more I look at it the surer
I am that numberedtuples will clean up a lot of fuzziness and wobbly
code. Thanks for the suggestion.) 

Deborah




More information about the Python-list mailing list