Module Is Not Callable
James Kew
james.kew at btinternet.com
Sat Jan 11 11:37:29 EST 2003
beno wrote:
> >>> import test
This actually imports the package which contains the standard library tests:
>>> help(test)
Help on package test:
NAME
test - # Dummy file to make this directory a package.
FILE
c:\python22\lib\test\__init__.py
...
> >>> import string
> >>> test()
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> TypeError: 'module' object is not callable
...and then attempts to call it -- as Python rightly points out, modules are
not callable. You'd get the same error if you tried:
>>> import os
>>> os()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: 'module' object is not callable
The module is a container for the objects defined within it -- for example,
in your code, you use the translate function in the string module by writing
string.translate(...).
> Testimonials.py
> ...
> def test():
...
OK. So your module is Testimonials; the function within it you want to call
is test(). So:
import Testimonials
Testimonials.test()
--
James Kew
james.kew at btinternet.com
More information about the Python-list
mailing list