1.import导入包的路径
In [4]: import sys In [5]: sys.path Out[5]: [‘‘, ‘/usr/bin‘, ‘/usr/lib/python35.zip‘, ‘/usr/lib/python3.5‘, ‘/usr/lib/python3.5/plat-x86_64-linux-gnu‘, ‘/usr/lib/python3.5/lib-dynload‘, ‘/usr/local/lib/python3.5/dist-packages‘, ‘/usr/lib/python3/dist-packages‘, ‘/usr/lib/python3/dist-packages/IPython/extensions‘, ‘/home/python/.ipython‘]
### 添加路径 In [6]: sys.path.append(‘/home‘) In [7]: sys.path Out[7]: [‘‘, ‘/usr/bin‘, ‘/usr/lib/python35.zip‘, ‘/usr/lib/python3.5‘, ‘/usr/lib/python3.5/plat-x86_64-linux-gnu‘, ‘/usr/lib/python3.5/lib-dynload‘, ‘/usr/local/lib/python3.5/dist-packages‘, ‘/usr/lib/python3/dist-packages‘, ‘/usr/lib/python3/dist-packages/IPython/extensions‘, ‘/home/python/.ipython‘, ‘/home‘]
2.reload重新导入模块
In [1]: import test1 In [2]: test1.test1() ----1-- In [3]: from imp import * #reload在imp包内 In [4]: reload(test1) Out[4]: <module ‘test1‘ from ‘/home/python/02-就业班/01-python高级-1/test1.py‘> In [5]: test1.test1() ----1-- ----2--
3.模块循环导入
## 模块a,b互相调用 ### cat a.py from b import b1 def a1(): print(‘----a1‘) b1() a1() ### b.py from a import a1 def b1(): print(‘---b1‘) a1() b1()
时间: 2024-11-08 08:27:16