Hello,
I just "thought" I understood how importing and modules work but obviously I need more schooling.
Here is an example program (just a test case of somerthing I'm doing that is much bigger in scope and scale) and a module:
quick.py
import gtk
from quick_window import *
w.show_all()
gtk.main()
quick_window.py
w = gtk.Window()
w.connect('destroy', lambda w: gtk.main_quit())
l=gtk.Label('Hello')
w.add(l)
running I get
$ python quick.py
Traceback (most recent call last):
File "quick.py", line 2, in <module>
from quick_window import *
File "/home/woodnt/Dropbox/python/weather_project/plugins/quick_window.py", line 3, in <module>
w = gtk.Window()
NameError: name 'gtk' is not defined
To get it to work, I have to also import (er, reimport) gtk in the module like so:
import gtk
w = gtk.Window()
w.connect('destroy', lambda w: gtk.main_quit())
l=gtk.Label('Hello')
w.add(l)
Why should I have to import gtk more than once? Does that mean that I have 2 "gtk's" in memory?
Do I have to import everything within each module that I need within that module?
I know each module has it's own namespace, but I thought it also inherited the "globals" including imported module from the calling program.
I had been under the impression the from module import * is like cutting and pasting the code right into that location. Is there another way to do that?
Help is greatly appreciated.
Narnie