Reading Between the Lines --- stuck, please help


File Input/output - Reading Between the Lines

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

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

01. Declare a new variable my_file and store the result of calling open() on the "text.txt" file in "r"ead-only mode.
02. On three separate lines, print out the result of calling my_file.readline(). See how it gets the next line each time?
03. Don't forget to close() your file when you're done with it!)

should read these three lines in file "text.txt":
I'm the first line of the file!
I'm the second line.
Third line here, boss.

Replace this line with your code. 
my_file = open("text.txt", "r")

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




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

you are trying to open an existing read modus.....
If you use following code
you will see which files are available....

import os
print "==show us the existing files =="
files = [f for f in os.listdir('.') if os.path.isfile(f)]
for f in files:
    print str(f)


With following code
you will do a test of the existence of text.txt file
and if the file text.txt is not found
you will create the text.txt file

import os
print "== if the file doesn't exist, create one =="
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")

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

== discussions / opinions ==