How to run a py file from another py file?

Hey so i’m trying to make a game hub where it lists the games in numbers. (1,2,3,4,5,6)
Say i type “2”, I want “2” i want “2” to be associated with running
( i already got the game hub setup, I just need to figure out how to run a py project from another py project"
maybe “py tictactoe” how would i do this?

Here is the code for my game hub if you are interested.

from colorama import Fore, Style
print("""
┌────────────────────────────────────────────────────────────────┐
│    _              _          _                         _       │
│   / \     _ __   (_) __  __ | |_   ____   ___   _ __  ( )  ___ │
│  / _ \   | '_ \  | | \ \/ / | __| |_  /  / _ \ | '__| |/  / __|│
│ / ___ \  | | | | | |  >  <  | |_   / /  |  __/ | |        \__ \│
│/_/   \_\ |_| |_| |_| /_/\_\  \__| /___|  \___| |_|   _    |___/│
│  __ _    __ _   _ __ ___     ___    | |__    _   _  | |__      │
│ / _` |  / _` | | '_ ` _ \   / _ \   | '_ \  | | | | | '_ \     │
│| (_| | | (_| | | | | | | | |  __/   | | | | | |_| | | |_) |    │
│ \__, |  \__,_| |_| |_| |_|  \___|   |_| |_|  \__,_| |_.__/     │
│ |___/                                                          │
└────────────────────────────────────────────────────────────────┘
""")

print(f"{Fore.LIGHTWHITE_EX}{Style.BRIGHT}Welcome to my game hub, Please select a game to play!")
print("""
┌───___──────────────────────────────────┐
│ / ___|   __ _   _ __ ___     ___   ___ │
│| |  _   / _` | | '_ ` _ \   / _ \ / __|│
│| |_| | | (_| | | | | | | | |  __/ \__ \│
│ \____|  \__,_| |_| |_| |_|  \___| |___/│
└────────────────────────────────────────┘""")


game_list = {"1." : "RockPaperScissors",
             "2." : "Cat quiz",
             "3." : "Computer quiz",
             "4." : "Salary classer",
             "5." : "Carp sizer", 
             "6." : "%Under development%",
             " "  : " "}
for key, value in game_list.items():
    print(key, value)
player_input = input("Select a numbered associated with a game to play that game!")
if player_input == "1" :
    # this is where im stuck. cant figure out how to run a py file from here. Looking for something like py.run ( file path )

There two ways you could do this.

  1. Use the python subprocess module and use subprocess.run() to execute the command to start the game.
  2. import the game python module and call the function that starts the game.

Sorry i forgot to mention that they are terminal games so like mini projects, Not actual “Games”. Though how would subprocess.run() look like fully functional? ( ex: subprocess.run(TicTacToe.py). ( or the path, or just something completely different ) lmk

Like this:

 subprocess.run(["/path/to/TicTacToe.py"])

That expects the python file itself to be executable. If not, tell
Python to run it:

 subprocess.run(["python3", "/path/to/TicTacToe.py"])

Adjust "python3" to be the Python executable you need.

if the game (script) requires command line arguments, provide them as
more strings after the script.

Docs: subprocess — Subprocess management — Python 3.12.4 documentation

To run with the same executable, as is required for IDLE, start args with sys.executable. If the program progx is on sys.path and hence importable, one might continue with '-m', 'progx'.

I get this error. File "c:\Users\Name removed\Desktop\call function.py", line 3 subprocess.run(["python3", "C:\Users\name removed\Desktop\Rock paper scissors.py"]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`` SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

And yes it’s Rock paper scissors. Forgot that i was rock paper scissors instead of tic tac toe but that shouldn’t make a difference.
here is the code subprocess.run(["python3", "C:\Users\isaac_mlz5gnw\Desktop\Rock paper scissors.py"])

and yes i did do “import subprocess” above all this code but it wouldnt format the code in here if i included that