How can I make one python file to run another?
For example I have two .py files. I want one file to be run, and then have it run the other .py file.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are more than a few ways. I’ll list them in order of inverted preference (i.e., best first, worst last):
import file. This is good because it’s secure, fast, and maintainable. Code gets reused as it’s supposed to be done. Most Python libraries run using multiple methods stretched over lots of files. Highly recommended. Note that if your file is calledfile.py, yourimportshould not include the.pyextension at the end.execfile('file.py')in Python 2exec(open('file.py').read())in Python 3os.system('python file.py'). Use when desperate.