Outline for February 15, 2012
Reading:
§13
File I/O
Opening and closing:
open(filename, mode)
,
close()
Reading:
readline()
,
readlines()
,
read()
,
read(n)
Writing:
write(str)
,
writelines(list)
Examples
Print out a named file [
fileio1.py
]
Print out a named file and prepend line numbers [
fileio2.py
]
Store the output in filename.lst [
fileio3.py
]
Reading a URL [
geturl.py
]
Opening a URL
Reading the page as a string (utf-8, us-ascii, iso-8859-1, etc.)
A PDF version is available here.
ECS 10, Basic Concepts of Computing
Winter Quarter 2012