473,288 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,288 software developers and data experts.

importing modules question

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.

Oct 18 '07 #1
2 1276
got it figured out. nevermind.

Oct 18 '07 #2
On 10/18/07, warhero <be*******************@gmail.comwrote:
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
Oct 18 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: qwweeeit | last post by:
The pythonic way of programming requires, as far as I know, to spread a big application in plenty of more manageable scripts, using import or from ... import to connect the various modules. In...
0
by: Brandon Metcalf | last post by:
I come from a Perl and C background and have been given an application written in Python to maintain and I know very little about Python. I'm having trouble at run time with importing modules. ...
6
by: Kamilche | last post by:
I have a large project that is getting complex, and I would like to print the docstrings without importing the modules. The only Python utility I could find references is apparently defunct and...
1
by: James Stroud | last post by:
Hello All, I have two modules that I use interchangably depending on the circumstances. These modules are imported by yet another module. I want the "importation" of these two alternatives to be...
6
by: Walter Brunswick | last post by:
What is the best way to import all modules in a directory (and possibly a subdirectory/subdirectories), possibly including conditionals, such as regexes?
1
by: ANSWER | last post by:
Is there any way I could disable user to create a new database and import all of my tables and queries into his database. I make .mde, disable shift+Enter, make logon users module (with your help...
14
by: T. Crane | last post by:
Hi, When troubleshooting code that's saved in a text file, I often find that I want to make a change to it, re-save it, then reimport it. However, just typing import myTestCode doesn't...
0
by: Martin P. Hellwig | last post by:
Hello all, I had some troubles in the past how to arrange my packages and modules, because I usually don't develop my stuff in the Lib\site-packages directory I have some troubles when importing...
7
by: Hussein B | last post by:
Hey, Suppose I have a Python application consists of many modules (lets say it is a Django application). If all the modules files are importing sys module, how many times the sys module will be...
2
by: Robert Dailey | last post by:
Hi, I'm currently using boost::python::import() to import Python modules, so I'm not sure exactly which Python API function it is calling to import these files. I posted to the Boost.Python...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.