Python练习-跨目录调用模块

层级结构:
dir1
---hello.py
dir2
---main.py
其中,hello.py:
def add(x,y):
return x+y
main.py如何能调用到hello.py中的add函数。

1.hello.py,灰常的简单

1 # 编辑者:闫龙
2 def add(x,y):
3     return x+y

2.main.py,稍微有点意思:

1 # 编辑者:闫龙
2 import sys
3 sys.path.append("D:/MyPythonProject/S4_D34/dir1")
4 import hello
5 print(hello.add(1,2))

以上请自行理解

posted @ 2017-04-26 20:32  DragonFire  阅读(583)  评论(0编辑  收藏  举报