How to run files that are not named main.py?
By default, repl runs files that are main.py but If I want to run someother file. How can I run it?
There are two ways to do this.
.replit file changes what file is being run.
<file> to your other file. Maybe
Importing files will allow you to run both files one after the other.
import dummy # ... your main.py code was here ...
make a file with name ".replit", and type:
language="python" run="python filename.py"
you can do things like:
#example.py def main(): print('xD') return 123
from example import main #You can import the file and use he functions main() #write 'xD' in the terminal x = main() print(x) #write 123 in the terminal
what you can do is put that file in a function and call it in main, I would say that is the easy whay.
To call a function in another file you have to do this in your main file or where you want to call it:
from example import *
example is the file you want to import where you have stored your function!
Hope it helped!
# different file def function(): print("hi") function()
# main.py from other file import function
Now run it, and it will work
# other file def function(): print("hi") function()
# main.py import filename
Any of those should work