Python file in one package invokes another instance of the package file

Source: Internet
Author: User
Tags testim

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.