Answers for "how to run a file in python"

6

run py file in another py file

os.system('python my_file.py')
Posted by: Guest on April-13-2020
1

python launch file

#how to open file with the default application for that file set by the OS

import os

filename = "PATH_TO_FILE" # EG. "C:UsersbaguetteDownloadsimage.png"

os.system("open " + shlex.quote(filename)) #MacOS/X
os.system("start " + filename) #windows

#Information and more available at 
#https://stackoverflow.com/questions/434597/open-document-with-default-os-application-in-python-both-in-windows-and-mac-os
Posted by: Guest on October-10-2020
12

run python file using python code

exec(open('file.py').read())
Posted by: Guest on May-24-2020
6

how to execute a python file from another python file

import  myfile

myfile.myfunction


#calls a specific function from within the file
Posted by: Guest on August-30-2020
0

How to run a File using python

import subprocess  #imports the module thats needed
subprocess.call([r'C:UsersRonDesktopTestcurrent_date.bat'])  #runs the file in the given directory
Posted by: Guest on November-05-2021

Code answers related to "how to run a file in python"

Python Answers by Framework

Browse Popular Code Answers by Language