Ask coding questions

← Back to all posts
How do I run my second file?
h
hvaandres (6)

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.

Comments
hotnewtop
lfchao (3)

Create a file named ".replit" to include

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

If your filename contains space,

run = "python3 'other file.py'"

[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"