How do I run my second file?
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.
lfchao
Create a file named ".replit" to include
language = "python3"
run = "python3 other.py"
If your filename contains space,
run = "python3 'other file.py'"
munalesumit
@lfchao thank you so much
B0tDevel0pment
@lfchao how would I add multiple files to this?
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"
Thank you for your help! @malvoliothegood