2/9 Does not recognize 'output.txt'


When I hit 'Save and Submit', it returns:
Traceback (most recent call last):
File "python", line 1, in <module>
IOError: [Errno 2] No such file or directory: 'output.txt'

and Oops, try again. Did you create a variable called my_file?
My code:
my_file = open("output.txt", "r+")


Get into this habbit when looking for a file. They need to add this little bit to the course because it is not common sense but something you learn.


    print("Attempting to open file")
    file  = open("some_txt_file.txt", "r")
    print("File Opened")
except IOError:
    print("Failed to load file!")
    file = open("some_txt_file.txt", "w+")
    print("File Created!")


Click on the output.txt tab and change something inside file. For example: press "Enter" at the first line in the file. Then execute your code again. :smile:


Does output.txt have anything in it beforehand? Here's my code: my_file = open("output.txt", "r+") It seems to be the same as yours...maybe restart your browser or refresh the page.


Your code is fine, I tried it and it works.


that worked for me but begs the question, why?


i prefer this module to try/except blocks tbh


I can see why. Keep up the good work!


That did it. Actually had to poke in and out of the "text.txt" file a couple of times, then it worked.