Python calls other python scripts to call python scripts.

Source: Internet
Author: User

Python calls other python scripts to call python scripts.

This example describes how to use python to call other python scripts. The specific method is as follows:

This instance calls the md5get. py script in the current directory. The Code is as follows:

Import OS import logging import subprocess log = logging. getLogger ("Core. analysis. processing ") INTERPRETER ="/usr/bin/python "if not OS. path. exists (INTERPRETER): log. error ("Cannot find INTERPRETER at path \" % s \". "% INTERPRETER) processor =" md5get. py "pargs = [INTERPRETER, processor] pargs. extend (["-- input = inputMd5s"]) subprocess. popen (pargs)

I hope this article will help you with Python programming.


How can I call other python scripts in a python script to run it?

If it is the same directory: import 1, 3, 5
If they are not added to the system variables first:
Import sys
Sys. path. append ('path \ 1 ')
Sys. path. append ('path \ 3 ')

Sys. path. append ('path \ 5 ')

Directly import

Another python script with parameters is called in the python script.

Cmd = '/home/menglin/androguard/androaxml. py-I {}| grep "android. permission. "'. format (path) p1 = subprocess. popen (cmd, stdout = subprocess. PIPE, shell = True)

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.