gett error message: "TypeError: 'int' object is not callable"

Tom Kermode tkermode at gmail.com
Thu Jul 9 12:06:45 EDT 2009


Hi,

   Do you know a good way to avoid running into this problem?  It
makes sense to suggest not calling variables the same names as
built-in functions, but that's hard for a new python programmer who
doesn't already know what all the built-in functions are. Over time a
programmer will learn which names to avoid, but it's a bit of a
pitfall early on.

Cheers,
Tom



2009/7/9 Richard Brodie <R.Brodie at rl.ac.uk>:
>
> "Nick" <nleioatt at gmail.com> wrote in message
> news:e54c4461-c0b7-42fb-8542-cefd7bf5f89f at h18g2000yqj.googlegroups.com...
>
>> file = open(prefix1)
>> text = file.readlines()
>> len = len(text)
>
> You have redefined two built-in functions "file" and "len" in the first three lines.
> This is usually considered poor practice. Stick to meaningless variable names,
> it's safer (only joking).
>
> TypeError: 'int' object is not callable". This means that something you thought
> was a function is in fact an integer. It's helpful to post/look at the line number of
> the error; "how is this line failing", is much easier to answer than
> "how is my program failing".
>
> print len(fields)
>
> Here len is an integer, because you redefined it in line 3. I'm guessing this is the
> problem.
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://www.kiloday.com
http://www.fourstopspast.com



More information about the Python-list mailing list