#4 Reading


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()


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")

This will give you a file to open and read.


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