Python refers to modules in different folders in the order in which they are called, ① modules that have classes in the calling module. Class (). Method () ② no class: module. Method ()
The test package testim.py calls the method Craw1 () method in testim1.py in the Test1 package and outputs the result:
testim.py
#Coding:utf-8
# testim.py in the test package, to invoke the method Craw1 () method in the testim1.py in the Test1 package
ImportSyssys.path.append ('C:\\pythonwork\\test1') #加入路径, add a directory
# Print Sys.pathImporttestIm1classTest_im (object):defCraw (self):Print 'This is Testim'testim1.test_im1 (). CRAW1 ()if __name__=='__main__': Im=Test_im () Im.craw ( )
testim1.py
# Coding:utf-8
# testim1.py is located in the Test1 bag
class test_im1 (object): def craw1 (self): Print ' This is testIm1 ' if __name__ ' __main__ ' : = test_im1 () im.craw1 ()
Reference: Python references for modules in different folders
Python file in one package invokes another instance of the package file