Flat CSV Files
00:19 This can be addressed through saving things out to some sort of storage, usually your disk drive. A side benefit of this is if it’s done well, it can be used to interact with more data than can be held in memory at any one time.
Flat file storage is a generic term for text-based files that typically can be read by a person. There are many different formats. Some common ones are CSV, the one which I’ll be using shortly, JSON, and the granddaddy of angle brackets, XML. Let’s go look at a program that uses Python’s
csv module to see the kinds of things that can be done with a flat file format.
01:37 In the case of special characters, for example, wanting to have a comma, you typically surround the value in quotes. CSV is a loosely defined thing. You will run into variations on how to use it, but the format here is what Excel uses and being one of the most popular programs on the planet weighs pretty heavily.
int. I loop through each row of data, adding the author’s name and publisher’s name into the respective dictionaries to form a count of occurrences. After that, I print out a summary of how many instances of each author name and of each publisher. Let’s go run this.
03:34 This is because everything is from the rows’ perspective, which in this case is the book. If I want to add the age of an author, technically I can do it, but I’d have to store it on each of the four instances of King’s books.
03:48 If I need to make a change, I’d have to do that in all four places. Essentially, any data associated with the book is just that—it’s an attribute of the book. I can’t really interrelate different items easily.
Become a Member to join the conversation.