Skip to content
← Back to Community
Why I can't run my second file
Profile icon
AshkiKudzma

I want to run my second python file but it always run whatever i have in main.py but not in second file i made.

Voters
Profile icon
LinranWu
Profile icon
sabiha1011
Profile icon
prasannarames
Profile icon
NinaGething
Profile icon
ShreehariFating
Profile icon
Eiriko
Profile icon
dysmenorrhea
Profile icon
Princekumar63
Profile icon
Chesed763066
Profile icon
P4rv
Comments
hotnewtop
Profile icon
HaykAprikyan

Ctrl+Shift+P > Open Shell > type in "python [second file name.py]"

Profile icon
chrisbarai

@HaykAprikyan how you guys manage your python file
by making a single repository for a single file or by some other way

Profile icon
awesomefireligh

@HaykAprikyan hi i was just wondering, but this is go on forever?

Profile icon
longtrenton529

@awesomefireligh This was 10 months ago lmao

Profile icon
awesomefireligh

@longtrenton529 I know, I was just asking in hope of an answer. XD

Profile icon
AliBaba1

To do this
go to your main.py file
and write the following code in it

from filename import *

Remember replace filename in code with your desired filename to be run
Note: do not use keywords as your filenames.

Profile icon
aayushich6

@AliBaba1 It is working but then at the bottom it is showing an error.

Also, how would i import another file inside a folder??

Profile icon
timmy_i_chen

Here's an example of using multiple files in python: https://repl.it/@timmy_i_chen/multi-files-demo

Profile icon
paulfears

that is because multible files are designed to be object oriented
you can run the other file by turning it into a class or function and importing it with the import command

or you could add this to main.py

import os
print(os.popen("otherfile.py").read())

Profile icon
chrisbarai

@paulfears means we should only keep one file(main.py) in one repository?