

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I make one Python file run another?
There are multiple ways to make one Python file run another.
1. Use it like a module. import the file you want to run and run its functions. For example, say you want to import fileB.py into fileA.py, assuming the files are in the same directory, inside fileA you'd write
import fileB
Now in fileA, you can call any function inside fileB like:
fileB.my_func()
2. You can use the exec command.
execfile('file.py')
executes the file.py file in the interpreter.
3. You can spawn a new process using the os.system command.
For example
os.system('python my_file.py')
- Related Questions & Answers
- How can I source a Python file from another Python file?
- How can I position JButtons vertically one after another in Java Swing?
- How many Python classes should I put in one file?
- How can I run a Linux command using Python CGI script?
- How can I make a time delay in Python?
- How to move a file from one folder to another using Python?
- How to make loops run faster using Python?
- How do I include a php.ini file in another php.ini file?
- How we can copy Python modules from one system to another?
- How can I make jQuery animations smoother?
- How do I run two python loops concurrently?
- How can I append a tuple into another tuple in Python?
- How to read data from one file and print to another file in Java?
- Can i refer an element of one array from another array in java?
- How to run Selenium tests in multiple browsers one after another from C# NUnit?
Advertisements