Please answer if I make 2nd file named second.py and print(“Hi”) but I see always Hello world in the console. Please sir answer:sob:
Hey @AseerAhnaf!
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.
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:
Replit is always going to run main.py unless you tell it not to. not-ethan shows you how to tell replit to run a different file, but alternatively you can keep main as it is, and just have main run the code from your other file.
The easiest way to run code from another file is to define a function and import + call it in main:
#main
import file2
file2.func()
#file2
def func():
#dostuff
In addition to @ThomasWarenski’s solution, there is an unsuggested way to do so, which is directly import and ignore it.
i.e:
#main.py
import second
#rest of code here
#second.py
#code here
That’s how python works, and you don’t need to worry about re-indenting your code under a brand new function. Though this exact reason is why it is a good practice for if __name__ == "__main__"
in your code, preventing code above to work.