python open and read file with repl.it
how to open and read file with repl.it on line
HappyFakeboulde
Add a file in the editor
Give it a name
In your program put f = open(filename, "r")
where filename is the name of the file you created
To read from the file put t = f.read()
where t is the name of the variable to save it in
Remember to close the file object with f.close()
It doesn't work for me. I don't know why. I enter this (after having uploaded my file in replit):
f = open(test.txt, "r")
I have this error code:
raceback (most recent call last):
File "main.py", line 2, in
f = open(test.txt, "r")
NameError: name 'test' is not defined
I tried with several files types (xlsx, csv...)
Do you know what I do wrong ?