importing modules question

Amit Khemka khemkaamit at gmail.com
Thu Oct 18 02:58:26 EDT 2007


On 10/18/07, warhero <beingthexemplarylists at gmail.com> wrote:
> Hey all, sorry for the totally newb question. I recently switched over
> to python from ruby. I'm having problems figuring out how module
> importing works.. as a simple example I've got these files:
>
> /example/loader.py
> /example/loadee.py
>
> loadee.py
> class loadee(object):
>     def __init__(self):
>         print "loadee"
>
> loader.py
> import loadee
> if __name__ == "__main__":
>     l = loadee()
>
>
> When I run the loader file I get a TypeError: TypeError: 'module'
> object is not callable

'import module' statement imports the 'module' object and binds the
name to the local namespace. Any names defined in the module will have
to referenced by module.module_object

so you need to do something like this:
import loadee
if __name__ == "__main__":
     l = loadee.loadee()

Alternatively you can directly import the objects defined in a module by :

from loadee import loadee
if __name__ == "__main__":
     l = loadee()

cheers,
-- 
--
Amit Khemka



More information about the Python-list mailing list