TypeError: 'module' object is not callable

R

randomtalk

Hello everyone!
i have the following test code:
class temp:
def __init__(self):
self.hello = "hello world!"
def printworld(self):
print(self.hello)
t = temp()

and i tried to call profile('t.printworld()')

but i received the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: 'module' object is not callable

I'm not sure what is wrong exactly, if anyone can point me to the
right direction, it would be much appreciated!
 
K

kyosohma

Hello everyone!
i have the following test code:
class temp:
def __init__(self):
self.hello = "hello world!"
def printworld(self):
print(self.hello)
t = temp()

and i tried to call profile('t.printworld()')

but i received the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: 'module' object is not callable

I'm not sure what is wrong exactly, if anyone can point me to the
right direction, it would be much appreciated!



If you're using the profile module, you need to do something like

profile.run('t.printworld()')

Good luck,

Mike
 
7

7stud

Hi,

I can't find any documentation on the profile() function. But it
might take a function reference as an argument and not the string you
are feeding it. For instance:

profile(t.printworld)

Note the difference between:

t.printworld
t.printworld()

The latter executes the function and then replaces the function call
with the return value of the function.
 
G

Gabriel Genellina

and i tried to call profile('t.printworld()')

but i received the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: 'module' object is not callable

It's always better to post the *whole* code.
I assume you wrote:
import profile
profile('...')
But profile is the module name; you want to call the `run` function inside
the profile module instead:

import profile
profile.run('t.printworld()')

Look at the docs for the profile module at
http://docs.python.org/lib/lib.html or typing help(profile) at the
interpreter prompt.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top