Ask coding questions

← Back to all posts
only main.py files is running. How to run the other files .py files
mail2kvanitha (2)

Hi,
I am newbie to REPL. I am just checking how to use python online. I created a file but when ever i run my pythion script, it always runs the main.py only. How to made the compiler to run my file?

Comments
hotnewtop
ApoorvAgrawal (51)
  1. Make a file named .replit
  2. Do this in the new file:
run = "python3 hello.py"
  1. If you want to delete main.py
  2. right click and go to the command pallet (or press F1)
  3. click on shell and a bash prompt should appear
  4. type rm main.py
chrisbarai (0)

@ApoorvAgrawal after deleting the main.py file will i able to compile other files or i have to keep single file only different repositories?

PythAthu (0)

Hi @mail2kvanitha, I think you should run this code if the file is in a folder: from foldername import filename with or if you have the file outside any folder then you have to run this code: import filename. And if you put an extension eg: filename.py then it will be and invalid syntax.
Thanks
Regards,
@PythAthu

PattanAhmed (1397)

@mail2kvanitha Hi,
I think You can import that file only if it is under a folder, As a project, Not just as another individual file...
So,
You can create a folder and name xxx and put that two files under that and can type import command and try:- Your code should look like this.:-

import xxx
# And can use any code from that file.

Make sure that two files are under one folder anywhere whether it may be Repl.it or other.

Hope this helps.
Please mark my answer if this helps.

Muffinlavania (1515)

just import hello in main.py

import hello

then if you have this in hello.py,

print("I like turtles")

it will print that and whatever

Coder100 (17034)

Hi! There are 2 ways to do it:

Importing the file

# main.py
import hello
# now the other file will be run along with yours!

Configuring the run button

Create a .replit file:

run="python hello.py"
Bookie0 (5967)

Hi!

you have to do this: from file_name import * (the star sign * means everything) and replace file_name with what you want. in your case its hello

then when you press run it should print what you wrote in the other files.

Happy coding and hope this helps! =)

mail2kvanitha (2)

i want python to run my other file hello.py