Mary Margaret

In this exercise, you're going to use object serialization to allow two distinct Python modules pass a dictionary back and forth, while they are running independently of each other.

You will execute each module seperately, and each one will augment a dictionary, and then serialize it to a file.

Setup

mkdir -p ~/workspace/python/exercises/memories && cd $_
touch mary.py
touch margaret.py

Requirements

  1. Create a mary.py module that contains a Mary class.
  2. Create a margaret.py module that contains a Margaret class.
  3. Each module must accept one command line argument that is a message to add to a list (see example below).
  4. Each module must be able to serialize a dictionary to a file named messages.
  5. Each module must be able to deserialize the dictionary stored in messages.
  6. Each module, after the object is deserialized from the file, must add the message to the appropriate list in the dictionary.
  7. Each module must handle exceptions properly. You may encounter the following while testing your logic.
    1. FileNotFoundError
    2. EOFError
    3. KeyError

Tip: Make sure you import sys for the command line arguments, and pickle for serialization.

Dictionary structure
{
    "Mary": ["Hi, I'm Mary", "I like jet planes"],
    "Margaret": ["Hi, I'm Margaret", "I like cookies"]
}
Command line syntax
python mary.py "Hi, I'm Mary"