Reputation: 75
Strange problem when importing modules:
File structure:
pages/
test.py
spawn.py
From spawn.py, if I do
from pages import test
everything works as expected.
If I do
from pages import *
I get
NameError: name 'test' is not defined
I don't get ImportError. I have commented out everything but two lines of code. I have init.py in the 'pages' dir, not that is should matter since I'm able to import just not use. I have tried changing filenames. Have tried on different machines, both Debian 6.0 though. Python version 2.6.6
Any ideas?
Upvotes: 0
Views: 2365
Reputation: 107608
You have to put import test
in pages/__init__.py
.
Just because pages
is a module does not mean it magically imports all the files in the same folder. You still have to name the modules you want to import (or write code that imports them automatically).
Upvotes: 1
Reputation: 11140
It matters because the pages/__init__.py
contains the symbols which from pages import *
will import
Upvotes: 0