Run files other than main.py

Question:
How can i execute a replit code in a file which is not named main.py

Replit Profile: https://replit.com/@ansanagarwal

Hey @ansanagarwal, welcome to the forums!

Just click the next to “Files” then click “Show hidden files”. Next click on the .replit file and finally you can change the entrypoint to whatever file you want to run.

Images

Dots

Show hidden files

edited

You should also see the docs on how to configure a Repl: https://docs.replit.com/programming-ide/configuring-repl

And if you want to run the last edited file, take a look at this post:

1 Like

you can also just run python file.py (replace file.py with the name of the file + .py) in shell, this won’t work with the run button and webservers or whatever are not created, you’re gonna need to change .replit for that.

1 Like

Well, I depends on what type of file you want to run, and if you want to run it when the “Run” button is pressed or when it gets to a certain line in your Python file.

If you want to do it inside of the Python file, then you can do this

import subprocess

subprocess.run("./file.sh") # If you wanted to run a shell file
#You can change the inside of the " " 's to whatever command you can run in the "Shell" tab. Like Ls or Python file_here.py

If you just don’t want a Python file either switch to a blank or another language template (easiest). Or you could just change the .replit file, it’s kinda complicated though, and you may break something. But if you want to go through the pain, just configure the “entrypoint” to whatever file you want to execute and then change the part where it says “python”, “main.py” to whatever command you have to run in the shell to execute the file. (EX. “./main.sh” or “./”, “main.sh”

What if you wanted to run a file of another type in a Python repl? In fact, I would say that you interpreted it wrongly. OP wants to run another Python file, because they used the word ‘renamed’, suggesting that it was renamed from main.py to somethingelse.py. I could be wrong, but this is how I interpreted.

Actually, this would be run, not entrypoint.
The configuration for a specific language repl is such that you can’t run a different language on it? You can’t run a HTML on a Python repl in the .replit file.

2 Likes