Chapter Three Exceptional Handling and Input and Outputs
Chapter Three Exceptional Handling and Input and Outputs
Exception
handling and
input and output
files
File input and
output
• Files are manipulated by creating a file object
• f = open("points.txt", "r")
f = file("foo", "r")
We read a line
line = f.readline()
from file object f
print line,
ct
f.close()
ob j e
s file
e th
i # Can use sys.stdin as input;
clo s
We # Can use sys.stdout as output.
Files: Input
input = open(‘data’, ‘r’) Open the file for input