Jul 27, 2009

How to call (or execute) a python file from another

Simply type in the following 2 lines of code in your python file (e.g. main.py), to call another python file (e.g test.py).

#Specify the path of the file you want to execute. E.g:
file_path = 'C:\\test.py'
#Execute the file using execfile

Copied from:

1 comment:

  1. Hello,

    I found your blog while I was trying to search a solution/ recipe for a problem I am trying to tackle... I am very new to python :(

    How can I run an executable file from a python script?

    for example:

    All the files (python script filename.py, executable file filename.exe, and the file that needs to be processed by the executable file filename.xyz) in the same directory.

    What do I need to write or include to my script (filename.py) so that it would start filemane.exe with filename.xyz and produce an output file / results?

    any help is greatly appreciated!

    you can direcly email me at




So, what did you think?