Skip to content
Sign upLog in
← Back to Community

How to run another python file (not the main.py) ?

Profile icon
FrancoisFaideau

It surely simple to do this but I don't know how.
Can anyone help me?
Thanks

Voters
Profile icon
Yash00100
Profile icon
NoeRandriambola
Profile icon
JoaoSerafim
Profile icon
krishna542
Profile icon
Oliver-NikolaiN
Profile icon
AlenZokovic
Profile icon
SwannMrn
Profile icon
MacSayto
Profile icon
SheebuKhan
Profile icon
lauraleimane
Comments
hotnewtop
Profile icon
eco27

make a .replit file and then you can put any run command in it
for example in your .replit file:
run = "python myfile.py"

Profile icon
omck

@MrEconomical
will this work if i make them files in one program?

Profile icon
chromebooker

@MrEconomical
im trying something similar (avoiding an annoying cyclic import) and i added it to the .replit and it still doesn't run the thing. could it be startCommand that starts those files? im basically trying to run flask while also running a command-line type of program

Profile icon
chromebooker

@chromebooker
ok i found the solution to my problem: run the flask on another thread

Profile icon
AlexanderTarn
  1. create a new file with (name).py
  2. write your code in it
  3. go to main
  4. import (name)
  5. use functions in file : (name).(function)(parameters)
Profile icon
AlexanderBirabe

Say you have a file called 'file2.py'. In your main.py file, type the line:
import file2

This runs the entire file as if it were a part of your main one, so any variables or functions in file2 will still be able to be referenced within main.py.

Profile icon
PAULHANNA

@AlexanderBirabe

Perfect. Works great.

Profile icon
pavanghai

Simple, from shell type
python filename.py
If your file is folder use
python folder/filename.py

Profile icon
HaroonMajid

Can anyone help me with this now? i have tried every solution and they (no longer) work.

Profile icon
ThirukumaranTha

@HaroonMajid
Make sure the file you dont want to run isnt in a folder cuz then it doesnt work and also dont include the .py at the end

Profile icon
abc3354

Hello !
If you want us to help you, you will have to ask a question or to post some code ;)
This is a guide on how to ask questions

Profile icon
ColinKirsch

how do i import a file to my damn repl? i need to know! may help with a project im working on and will help with [email protected]

Profile icon
alvinbengeorge

@ColinKirsch

Drag and drop works