Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Importing a package and looping through modules in the package

Reply
Thread Tools

Importing a package and looping through modules in the package

 
 
Dave
Guest
Posts: n/a
 
      02-10-2004
Hi Everyone,

I am trying to import a package and then loop through the modules
inside the package, but I'm running to a problem. Basically:
-----
I have a package called
regression.changepassword.unittests which contains test modules.
---
In a test agent module (called agent.a), I do the following:

from regression.changepassword.unittests import *
utilities.runTests("regression.changepassword.unit tests.")
----
in the utilities.runTests, I do the following:
for id in sys.modules.keys():
if id.startswith(testtype) and sys.modules[id] != None:
print "module id is: " + `id`
---------------------------------------------------
However, the loop is never executed since it seems the list of modules
in regression.changepassword.unittests is never added to the
sys.modules. If I import the tests one by one as the follwing:

from regression.changepassword.unittests import CPWD_2
from regression.changepassword.unittests import CPWD_3

Then the program works and loops through the test modules correctly.
Am I doing something wrong? Or that is how Python works and I have to
import modules one by one. I appreciate any help that you can offer
me and thanks for your time ( I apologize if my message is too long).

Thanks,
Bardia
 
Reply With Quote
 
 
 
 
Rich Krauter
Guest
Posts: n/a
 
      02-10-2004
On Mon, 2004-02-09 at 22:29, Dave wrote:
> Hi Everyone,
>
> I am trying to import a package and then loop through the modules
> inside the package, but I'm running to a problem. Basically:
> -----
> I have a package called
> regression.changepassword.unittests which contains test modules.
> ---
> In a test agent module (called agent.a), I do the following:
>
> from regression.changepassword.unittests import *
> utilities.runTests("regression.changepassword.unit tests.")



Do you have __all__ defined in your __init__.py in
regression.changepassword.unittests?

This part of the tutorial might help:
http://www.python.org/doc/current/tu...00000000000000

Rich


 
Reply With Quote
 
 
 
 
Dave
Guest
Posts: n/a
 
      02-10-2004
Rich Krauter <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> On Mon, 2004-02-09 at 22:29, Dave wrote:
> > Hi Everyone,
> >
> > I am trying to import a package and then loop through the modules
> > inside the package, but I'm running to a problem. Basically:
> > -----
> > I have a package called
> > regression.changepassword.unittests which contains test modules.
> > ---
> > In a test agent module (called agent.a), I do the following:
> >
> > from regression.changepassword.unittests import *
> > utilities.runTests("regression.changepassword.unit tests.")

>
>
> Do you have __all__ defined in your __init__.py in
> regression.changepassword.unittests?
>
> This part of the tutorial might help:
> http://www.python.org/doc/current/tu...00000000000000
>
> Rich


Hi Rich,

Thanks for your response. That was exactly what the problem was. I
should have gone through the tutorial more carefully .

Thanks,
Bardia
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing v reloading modules modules Peter Peyman Puk Python 0 03-19-2010 05:09 PM
RE: Importing modules through directory shortcuts on Windows Tim Golden Python 1 04-27-2006 07:01 PM
Importing modules through directory shortcuts on Windows Brian Quinlan Python 2 04-27-2006 07:27 AM
Importing modules from within other modules Tobiah Python 2 09-14-2003 09:18 PM



Advertisments