Outline for November 12, 2020

Reading: §7
Due: Homework 3, due November 13, 2020


  1. File Input and Output for text files
    1. Opening and closing: open(filename, mode), close()
    2. Reading: readline(), readlines(), read(), read(n)
    3. Writing: write(str), writelines(list)

  2. Examples
    1. Print out a named file [fileio-1.py]
    2. Print out a named file and prepend line numbers [fileio-2.py]
    3. Store the output in filename.lst [fileio-3.py]

  3. Examples
    1. Put lines in a file in random order [randlines.py]
    2. Read in a list of words from a file, then search it as requested; similar to linear search program [search-1.py]
    3. Now see how many words you checked total [search-1c.py]

  4. Word count programs: reading from files


UC Davis sigil
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.

Valid HTML 4.01 Transitional Built with BBEdit Built on a Macintosh