Pickling

In this project toolbox exercise you will be learning how to write Python data to disk and retrieve them later. This structure will be very useful for any situation where your program needs to have access to persistent data that it then modifies periodically. One way this can be used is to make a quick and dirty database.

Get Set

GitHub Classroom invite

The starter code will be in counter.py. It contains the function you should be implementing. The function has a descriptive docstring that explains what you will be doing along with a few unit tests. If you run the Python script without any arguments you will execute the doctests.

Learn About File Input and Output

There are many good resources to use to learn about files. Check out some of these resources:

Learn About Pickle

There are many good resources to use to learn about pickling. Check out some of these resources:

Implement the function update_counter

The basic idea is to open the counter file in rb+ (reading plus) mode if it exists and you are not resetting the counter, and in wb (writing) mode otherwise. Once the file is open you can either initialize the counter to 0 (if appropriate) or read the counter value (using load) and then increment it. To finish your implementation, use the dump function to store the resultant counter value to the disk.

Hints:

Turning in your toolbox assignment

To turn in your assignment, push your code to GitHub.