TypeError: 'list' object is not callable

Jussi Piitulainen jpiitula at ling.helsinki.fi
Thu Feb 6 10:34:24 CET 2014


wilsonmonde at gmail.com writes:
> Peter Otten wrote:
> > wilsonmonde at gmail.com wrote:
> > 
> > > TypeError: 'list' object is not callable
> > 
> > Hint:
> > 
> > > open = []
> > 
> > [...]
>
> > > with open(..., "rb") as csvfile:
> 
> i follow in
> http://www.dyinglovegrape.com/data_analysis/part1/1da3.php
> 
> still have error
> 
> what is the correct writing?

One way:

   # open = []
   with open(..., "rb") as csvfile:

Commenting out the assignment statement prevents it from doing the
damage before you try to access the original value of open.

Another way:

   with [](..., "rb") as csvfile:

This doesn't work any better but it makes the error stand out.

Yet another way:

   avaa = open
   open = []
   with avaa(..., "rb") as csvfile:

That is, save the original value of open in another variable, which I
here called avaa.

The best way is to omit the whole assignment altogether. Were you
using the list called open for something?

Oh, one more way!

   with open(..., "rb") as csvfile:
      ...
   open = []

That is, only shoot yourself in the foot after the work has been done!
Though, really, best not do it at all. The page you referred to,
doesn't.



More information about the Python-list mailing list