Ask coding questions

← Back to all posts
My newly added file.py won't work
SohamKh

Hello it's my first day coding and i am not familiar with replit.
my plan was to make diff files for different lecs but whenever i add a file from file tab and try to code in it won't work it'll just run the main.py

Answered by OldWizard209 [earned 5 cycles]
View Answer
Voters
SohamKh
Comments
hotnewtop
OldWizard209

You can do it by using a .replit file. Create a .replit file:

And using that, you can past this code:

Make sure you change the file name to whatever you want to run after the "python" in the first line.

SohamKh
OldWizard209

Mark answer as correct? @SohamKh

Bookie0

You have to import the file. So in main.py, add from [filename] import *. Change [filename] with the name of your file. The * is for importing everything from that file. You could also just do from [filename] import [functionname] and replace [functionname] with a function, variable, class, etc.

Lemme know if you have more questions.

Good luck! :D

OldWizard209

they can use a .replit. @Bookie0

Bookie0

as well. @OldWizard209

SohamKh

Thanks :)
ngl i didn't understand what u said it's literally my 1st day of coding @Bookie0

Bookie0

@SohamKh lol np if you want you can invite me to a repl for me to show you (if you want, it seems like you already have an answer) :)

NoelB33

Create a new repl for each file or import it and run a function inside of it.

NoelB33

If you create a new repl for each file then just copy and paste the code.