importing modules question

W

warhero

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

hm. Sorry, this is totally newb, this is the only switching pains I've
had.
 
A

Amit Khemka

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,
 

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,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top