Skip to content
← Back to Community
Running a program
Profile icon
TimiA

Hello,
I have created multiply python files however i am only able to run the first program (main.py). Is there any way of specifing the file i want to run everytime i want to run it?
Thanks

Voters
Profile icon
Toonchy
Profile icon
Bryonnag
Profile icon
satyanandamohap
Profile icon
LOUAN1234
Profile icon
AdibAziz
Profile icon
ShayanLsd777
Profile icon
BigManHash
Profile icon
DanielleSoh
Profile icon
alanaraf83
Profile icon
DorotheaDavidso
Comments
hotnewtop
Profile icon
MATTHEWBECHTEL

If he answered then you should Upvote their comment and give them the 5 cycles.
@TimiA

Profile icon
ash15khng

You'll have to move the code in main.py somewhere else first.
Then, add this in main.py:

a = input("Name of file to run (without py extension): ") __import__(a)

__import__(a) is just a function that imports your input, running your code.

Profile icon
JustARatherRidi

Hey TimiA, while ash15khng is correct, you usually don't have more than one starting point in a project, and that's why it was made this way. In repl.it and in Python projects in general, you have something along the lines of main.py that acts as the starting point of your project. The other files in your project may contain classes, methods, or constants that you can use within your project (using import and/or open).

If you have files that run independently to each other or do different things, it's probably a good idea to make them two separate repls (using the blue 'new repl' button up top) and not two files in the same repl.

However, if your two programs are independent of each other but are related, you might want to store the two repls in one folder. You can do this in your My repls page.

Hope this helped; if something confused you, I'll be more than glad to clarify!