Exercise 5 - reading between the lines. File does not exist bug
In what way does your code behave incorrectly? Include ALL error messages.
The file to be read
text.txt in does not exist until after you have made a change to it.
import os print os.listdir("./") my_file = open("text.txt", "r") print my_file.readline() print my_file.readline() print my_file.readline() my_file.close()
import os added to verify the bug. When you first load the exercise there are no files in the directory. If you run my code you get the following error:
 Traceback (most recent call last): File "python", line 3, in <module> IOError: [Errno 2] No such file or directory: 'text.txt'
If you make any changes to the
text.txt file the file will save and by listed in the
os.dirlist("./") function, and the exact same code will work. (Additionally if you try to run code while the
text.txt is focussed it will try to run the text file as python code)
What do you expect to happen instead?
The exercise to work without me having to look at the text file, or for the exercise to tell me I need to look at/change the text file.