开发者

python wildcard import

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 ImportE开发者_如何学运维rror. 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?


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).


It matters because the pages/__init__.py contains the symbols which from pages import * will import

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜