Skip to content
← Back to Community
How do I run my second file?
Profile icon
hvaandres

Here https://repl.it/@AndresHaro1/PythonCourse I have two different files where I'm trying to run the second file to see if it works or not but, I'm not able to do that since is reading the main.py file instead of the file called string_basics.py.

Voters
Profile icon
Elyk
Profile icon
mj-codings
Profile icon
mrghani
Profile icon
aliijaz0631
Profile icon
hvaandres
Comments
hotnewtop
Profile icon
[deleted]

You will need to import the code in string_basics into the main.py file. You can do it like so:

import string_basics
print(string_basics.sentence)
print(string_basics.sentence_two)
...and so on

Note that you need to prefix the sentence name with the name of the module. To geta round this you could use a different import syntax, like so:

from string_basics import *
print(sentence)
print(sentence_two)
...and so on

The import statement can be read as "from the string_basics module import all"

Profile icon
hvaandres

Thank you for your help! @malvoliothegood

Profile icon
lfchao

Create a file named ".replit" to include

language = "python3"
run = "python3 other.py"

If your filename contains space,

run = "python3 'other file.py'"

Profile icon
munalesumit

@lfchao thank you so much

Profile icon
SanyaRaj

@lfchao Is there any similar method for cpp?

Profile icon
B0tDevel0pment

@lfchao how would I add multiple files to this?