Lecture 14

Files for structured data

MCS 260 Fall 2021
David Dumas

Reminders

  • Project 2 posted
  • We'll talk about Project 2 a bit on Monday
  • Homework 5 posted, due Tuesday at 10am
  • JSON

    JSON stands for JavaScript object notation. It is a format for storing various types of data in text files.

    We'll discuss it in some detail on Monday.

    To motivate that discussion, let's work through an example program where it might be useful.

    Moving data around

    We have talked about how to read and write strings in text files.

    Often, files are used to hold structured data that is generated by one program, and used by another.

    Accomplishing that with file.read(), file.write(), and str.format() is possible, but tedious and error-prone.

    Count the words in a file and print a report:

    wordstats3.py

    Revision history

    • 2021-09-24 Initial publication
    • 2021-09-24 Add link to sample code; change title; move actual JSON content to lecture 15 slides