Text.txt does not exist Error


#1



my_file=open("text.txt",'r')
print my_file.readline()
my_file.close()

What is wrong with this?
It says

Traceback (most recent call last):
  File "python", line 1, in <module>
IOError: [Errno 2] No such file or directory: 'text.txt'


#2

yes, this exercise is indeed buggy, here is a good solution:

first write to the file, then read it.


#3

I tried to refresh but it did not work. Glitch maybe????????????? I also did the second thing but that didn't work either.


#5

Please make a new topic if you still struggle, since this topic is dedicated to helping microrunner75943


#6

That worked. Thanks "stetim94"

Code I used:

f = open("text.txt", "w")
f.write("Hello World!" + "\n")
f.write("Hello World!!" + "\n")
f.write("Hello World!!!" + "\n")
f.close()

my_file = open("text.txt", "r")

print my_file.readline()
print my_file.readline()
print my_file.readline()

my_file.close()


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.