導入模塊,這是一個Python新手問題:嵌套包
我有以下目錄結構:
test
-- test_file.py
a
-- b
-- module.py
其中test
,a
和b
是文件夾。 test
和a
都處於同一水平。
module.py有一個名爲shape
的類,我想在test_file.py中實例化它的一個實例。我該怎麼做?
我曾嘗試:
from a.b import module
但我得到:
ImportError: No module named a.b
請參閱http://stackoverflow.com/questions/72852/how-to-do-relative-imports-in-python。 – 2010-02-02 10:30:33