Outline for February 13
Reading
:
text
, §7
Due
: Homework 3, due on February 15 at 11:55pm
Characters and representations
How characters are represented internally [
chr.py
,
ord.py
]
Figuring out the position of a character in the alphabet
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
]
Same, but use
print
rather than
write
[
fileio4.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
Office: 2209 Watershed Science
Phone: +1 (530) 752-8060
Email:
[email protected]
You can also obtain a PDF version of this.
Version of February 11, 2019 at 8:10PM