Module import problems

Josiah Carlson jcarlson at uci.edu
Mon Apr 5 19:23:13 EDT 2004


> I had to resort to "from login import *" in main.py and then "import
> wx" (and other modules like urllib/webbrowser etc) in login.py and it
> all seems to work.

Sounds ugly.  I would stick with...

#in main.py
import login
import wx

#in login.py and others...
import wx


> I didn't occur to me that I'd have to import the modules used in each
> module file, I thought it would work just from the parent (main.py)
> file.

You were misunderstanding modules, namespaces, etc.


> I've also stopped myself from calling classes instead of defs (I had
> the whole class in the __init__ def previously) and removed most of my
> global variables.

What do you mean "calling classes"?  Show an example of what you were 
doing before, and what you are doing now, and I'm sure someone will tell 
you which is more "Pythonic" and/or which is a better design.


> Now I have twelve 1-6Kb files like login.py, plus an 18Kb main.py,
> instead of one 38Kb main.py to grep through!
> 
> So it was worth the struggle to clean up a bit....

Congrats.

  - Josiah



More information about the Python-list mailing list