Outline for November 12, 2020
Reading
: §7
Due
: Homework 3, due November 13, 2020
File Input and Output for text files
Opening and closing:
open(
filename
,
mode
)
,
close()
Reading:
readline()
,
readlines()
,
read()
,
read(
n
)
Writing:
write(
str
)
,
writelines(
list
)
Examples
Print out a named file [
fileio-1.py
]
Print out a named file and prepend line numbers [
fileio-2.py
]
Store the output in
filename
.lst [
fileio-3.py
]
Examples
Put lines in a file in random order [
randlines.py
]
Read in a list of words from a file, then search it as requested; similar to linear search program [
search-1.py
]
Now see how many words you checked total [
search-1c.py
]
Word count programs: reading from files
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email:
mabishop@ucdavis.edu
MHI 289I, Programming for Health Informatics
Version of November 12, 2020 at 10:42PM
You can also obtain a PDF version of this.