-----------------------------------------引入父級目錄
目錄結構:python
print_father.py引入上級目錄father.py模塊的sentence變量,代碼以下:
#注:須要引入的文件 E:\test\test176\test186\grandfather.pyapp
import sys
sys.path.append(r'E:\test\test176\test186') #python搜索環境變量中增長鬚要引入模塊所在路徑
from grandfather import sentence
print(sentence)3d
-----------------------
print_grandfather.py引入上級目錄grandfather.py模塊的sentence變量,代碼以下:blog
import sys
sys.path.append(r'E:\test\test176')
from grandfather import sentence
print(sentence)it
-----------------------------------------------------------------------引入父級子目錄test
引入父級子目錄,而且把增長變量寫在包所屬模塊__init__.py內import
目錄結構:變量