.close() fail in Python



I was curious what would happen if i ran my code without the .close() file since codecademy kept telling me it's a bad idea, which I ran it without the .close() command. After that I kept getting these two errors.

the errors i'm getting from the compiler is,

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

from codecademy i'm getting,

Oops, try again. Sorry, but I'm gonna need you to refresh the page! Don't worry your code is saved.

I expect this to print out the three lines in the text.txt file. I've refreshed my browser and even deleted my cookies/browsing history to try to make the errors go away. Any suggestions would be nice :slight_smile:

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


NVM solved it. I copied the sentences from the text.txt file and pasted it back into the same file. After that python recognized the file again. sorry for making a thread about this.


Most of the file i/o exercises misbehave one way or another.. Unmaintained course that they decided to poke at and then not fixing what they broke in doing so


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