Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

TypeError: object is not callable

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


gustafl at algonet

Jun 6, 2001, 5:43 PM

Post #1 of 4 (531 views)
Permalink
TypeError: object is not callable

Why this error?

I have done a class which is in placed in a directory within sys.path, and
the class works as intended when I test it by adding some main() code in
it. But when I call it from another module I get this strange error
"TypeError: object is not callable". No way I can get the same error in
Idle...

From the docs, it seems that it has something to do with the constructor,
so here is the constructor:

class Friend:
def __init__(self, id, file):
self.id = id
self.name = ""
self.emails = []
self.file = file
self.load()

Regards,

Gustaf Liljegren


matt at mondoinfo

Jun 6, 2001, 6:00 PM

Post #2 of 4 (503 views)
Permalink
TypeError: object is not callable [In reply to]

On 7 Jun 2001 00:43:10 GMT, Gustaf Liljegren <gustafl [at] algonet>
wrote:

>I have done a class which is in placed in a directory within
>sys.path, and the class works as intended when I test it by adding
>some main() code in it. But when I call it from another module I get
>this strange error "TypeError: object is not callable". No way I can
>get the same error in Idle...

From the docs, it seems that it has something to do with the
>constructor, so here is the constructor:

>class Friend:
> def __init__(self, id, file):
> self.id = id
> self.name = ""
> self.emails = []
> self.file = file
> self.load()

Gustaf,
It's hard to be sure what the problem is without seeing an example
that fails but if the problem in in the constructor, it seems likely
that it's in the last line since that's the only place that you're
trying to call something. If self.load is something other than a
method there, you'll get the error message you mention. You might try
printing self.load (note no parentheses) just before that line.

Regards,
Matt


paulp at ActiveState

Jun 6, 2001, 6:24 PM

Post #3 of 4 (512 views)
Permalink
TypeError: object is not callable [In reply to]

Gustaf Liljegren wrote:
>
> Why this error?
>
> I have done a class which is in placed in a directory within sys.path, and
> the class works as intended when I test it by adding some main() code in
> it. But when I call it from another module I get this strange error
> "TypeError: object is not callable". No way I can get the same error in
> Idle...

I'm going to guess that you have a class Friend in a module called
Friend.py and then do this:

import Friend

f = Friend()

You need to do this:

f = Friend.Friend()

If that isn't the answer, I'll need more info.

--
Take a recipe. Leave a recipe.
Python Cookbook! http://www.ActiveState.com/pythoncookbook


gustafl at algonet

Jun 7, 2001, 1:24 AM

Post #4 of 4 (510 views)
Permalink
TypeError: object is not callable [In reply to]

Paul Prescod <paulp [at] ActiveState> wrote:

>You need to do this:
>
>f = Friend.Friend()
>
>If that isn't the answer, I'll need more info.
>

Right! Obvious when you know it. :-)

Gustaf

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.