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

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

test包中testIm.py 调用 test1包中testIm1.py中的方法craw1()方法,输出结果:python 一个包中的文件调用另外一个包文件   实例

 

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 不同文件夹中模块的引用 

相关文章:

  • 2022-12-23
  • 2021-08-06
  • 2021-09-15
  • 2022-02-09
  • 2022-12-23
  • 2023-03-10
  • 2022-01-05
  • 2022-02-09
猜你喜欢
  • 2021-05-31
  • 2022-12-23
  • 2021-08-11
  • 2022-12-23
  • 2021-10-12
  • 2021-06-05
  • 2021-10-28
相关资源
相似解决方案