python 一个包中的文件调用另外一个包文件 实例

python不同文件夹中模块的引用调用顺序,被调用的模块中①有类的 模块.类().方法()   ②无类的:模块.方法()

test包中testIm.py 调用 test1包中testIm1.py中的方法craw1()方法,输出结果:

 

testIm.py

# coding:utf-8
# testIm.py位于test包中,要调用test1包中的testIm1.py中的方法craw1()方法
import sys sys.path.append('C:\\pythonwork\\test1') #加入路径,添加目录
# print sys.path
import testIm1 class Test_Im(object): def craw(self): print 'This is testIm' testIm1.Test_Im1().craw1() if __name__ == '__main__': im = Test_Im() im.craw()

testIm1.py

#coding:utf-8
# testIm1.py位于test1包中
class Test_Im1(object): def craw1(self): print 'This is testIm1' if __name__ == '__main__': im = Test_Im1() im.craw1()

 

参考: python 不同文件夹中模块的引用 

posted on 2017-05-17 11:43  一叶舟鸣  阅读(2449)  评论(0编辑  收藏  举报

导航