#4 Reading


#1



21. File Input/Output


File "python", line 1, in
IOError: [Errno 2] No such file or directory: 'output.txt'

Oops, try again. Did you create a variable called my_file?


Should be able to print on screen, the output file


my_file = open("output.txt","r")
print my_file.read()
my_file.close()


#2

Above your existing code, try opening an output file as 'w' and write a few lines to the file.

my_file = open('outout.txt', 'w')
my_file.write("first line of text")
my_file.write("second line of text")
my_file.write("third line of text")
my_file.close()

This will give you a file to open and read.


#3

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