Run button only runs no matter what program is open and being edited in the editor

Is there a way to redirect the Run Button to run the code I am writing in the editor and not just the code in the program?

Technically, there is not. Any python interpreter and program will run as the default program. There are ways that you can get another program to run using python code. One way to do this IN python code would be:

import os
os.system("python [programname].py")

Alternatively, you may create a python program that uses a definition so that you can run it in the terminal and get that program to start another. All you need to do is type the program name, excluding the “.py”. If you have this program in your file, click run. Wait for the program to stop, then in the console, type “open (“test”)”. Replace “test” with the name of whatever local python file you want to run. Remember to exclude “.py” from the string, the program will add it in.

import os
word = "null"
def open(word):
  os.system("python " + word + ".py")

Using the last code I provided, I may suggest that while you are testing your program, you make this code the file, so that whenever you need to, you can run whichever program you like.

This is actually inefficient, it’s probably better to just change the command and entrypoint in the .replit config file. Also you shouldn’t override the open function.

Thank you both. Your replies have been very helpful. Thanks again

1 Like

@PeterG10 You are welcome.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.