Outline for February 6, 2019
Reading
:
text
, §7
Due
: Homework 3, due February 18, 2019
Searching a list
Example use: linear search [
linsearch.py
]
Example use: recursive linear search [
rlinsearch.py
]
Files
What is a file?
What can you do with it? (For example, read, write, append)
Types of files (text, binary)
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 [
fileio1.py
]
Print out a named file and prepend line numbers [
fileio2.py
]
Store the output in
filename
.lst [
fileio3.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
]
Matt Bishop
Department of Computer Science
University of California at Davis
Davis, CA 95616-8562 USA
Last modified: Version of February 11, 2019 at 7:32PM
Winter Quarter 2019
You can get a PDF version of this