Python Forum
python run all py files from main py file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python run all py files from main py file
#7
Hi Gribouillis,

Superb ! your code worked , Clap
you are genius ! thanks for your help, you have saved my time.

Is there any other style way. I heard about multiprocessing\Multitreading\subprocess .run.



from pathlib import Path
import sys
this_dir = Path(__file__).parent
 
for args in [
    "add.py 10 20 30",
    "sub.py  40 20",
    "mul.py  2 2 2 2",
    "div.py   100 50"]:
    args = args.split()
    filename = this_dir/args[0]
    args[0] = str(filename)
    sys.argv[:] = args
    namespace = {'__name__': '__main__'}
    exec(filename.read_text(), namespace)
Reply


Messages In This Thread
python run all py files from main py file - by mg24 - Oct-11-2022, 05:16 AM
RE: python run all py files from main py file - by mg24 - Oct-12-2022, 04:41 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu BillKochman 13 1,388 Apr-24-2024, 05:47 AM
Last Post: Bronjer
  delete all files and subdirectory from a main folder mg24 7 1,752 Oct-28-2022, 07:55 AM
Last Post: ibreeden
  Python-for-Android:p4a: syntax error in main.py while compiling apk jttolleson 2 2,047 Sep-17-2022, 04:09 AM
Last Post: jttolleson
  Python code to read second line from CSV files and create a master CSV file sh1704 1 2,492 Feb-13-2022, 07:13 PM
Last Post: menator01
  how to run another function from main file Mekala 3 2,673 Aug-09-2020, 04:41 AM
Last Post: deanhystad
  Details of attachment files in a msg file such as file names save into a python list klllmmm 2 5,827 Nov-12-2019, 05:59 AM
Last Post: klllmmm
  Use Variables Generated from Functions in different files to use on the main file AykutRobotics 3 3,039 Jan-01-2019, 04:19 PM
Last Post: AykutRobotics
  Running a python tool transforming xml files into epub files silfer 7 5,597 May-10-2018, 03:49 PM
Last Post: snippsat
  Even if my file is "main.py",cannot run my project sylas 13 14,593 Mar-05-2018, 09:15 AM
Last Post: sylas
  Since PyCharm knows which file is "main", how can I tell it "run this project" sylas 7 8,266 Sep-03-2017, 11:48 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020