二、引入父级模块或者包

-----------------------------------------引入父级目录
目录结构: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


目录结构:变量

 

相关文章
相关标签/搜索