Ask coding questions

← Back to all posts
Running a program
TimiA (0)

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

TimiA (0)
JustARatherRidi (189)

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 and in Python projects in general, you have something along the lines of 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!


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

ash15khng (234)

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

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

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