Python Lesson 5 ERROR? (Reading Between the Lines - File Input/Output)


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

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

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


Apparently the problem seems to be that the Interpreter cannot access text.txt (see Error-Msg).
It is particularly annoying, since at this point I (or other people) have finished over 95% of the Python course, and just before the finish of the course, THIS ERROR-MSG prevents me from finishing & receiving the Python Achievement ... Maybe at least add an alternate way to finish the course (maybe autocomplete this section?)


seems to be a bug - i have had the same problem.
you can fix it, if you precede your code with:

import os
if os.path.exists('text.txt'):
    print "File exists"
    print "Creating the text.txt-file"
    my_file = open("text.txt", 'w')
    my_file.write("I'm the first line of the file!" +"\n")
    my_file.write("I'm the second line."+"\n")
    my_file.write("Third line here, boss."+"\n")


Hi @drpacket !

This issue has been addressed in this thread: 5/9

Please check it out. :slight_smile:


yes, thank you:) just saw it. Sry fro opening new thread


You're welcome.

Have fun coding! :wink:


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