Python program calls another Python program __python

Source: Internet
Author: User

Python programs call another Python program, and there are probably several ways to invoke it:

Here are two Python programs, assuming a.py and b.py two programs, respectively.

1, in the a.py inside call b.py inside function, have the following two kinds of situation

(1) In the same file directory-this time can be directly with import B (Note No. py) then function call with B.function ()

(2) Not in the same directory-this time need to add b.py to the program path, with

"From sys import path"

Path.append (0,sys.path[0]+ ' \ file path ')

"Form. File path. b.py Import fuction

2, in the a.py inside directly call b.py all the program

Import OS

Os.popen (' Python path/b.py ')

Don't use Os.system here ()

The difference is here: http://bbs.chinaunix.net/thread-3777538-1-1.html


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.