In this document, I wrote down the steps I took to create a script to display a menu to the user, request user to choose a menu option, add “Name” and “ID” lists, store lists as a pickle, unpickle and read data from binary files. I watched the videos from Module 7, reviewed the list of other exceptions from the web, and read the seventh chapter from the book “Python Programming for Absolute Beginners”. I encountered some challenges in pickling and reading from the file but was able to resolve them and also added some exceptions.
I displayed a menu with four options to the user. I requested the user to add “names” and “ids” in two lists.
Pickling means to preserve your piece of data in the format you stored. I saved each list (names and ids) as a pickle onto a binary file called “Appdata”.
When user selects this action, data is read from the selected file, the lists are unpickled and displayed back to the user.
I created four exception handling cases:
When user selects this action, a message is displayed to the user and they exit from the program
Results in PyCharm showing the user performing each of the actions succesfully:
Fig 1.1: Screenshot of the result in Pycharm
Fig 1.2 Screenshot of the exceptions in Pycharm
Fig 1.3 Screenshot of the unpickling exception in PyCharm
Results in Terminal displaying all user actions
Fig 2: Screenshot of the result in Terminal
https://github.com/ruby0606/IntroToProg-Python-Mod07
I started with a basic trial file where I defined my list data in the program instead of requesting user to add information. I then attempted pickling/unpickling actions and verified how the information looks. Once I was able to complete this properly, I went onto requesting data from user and performing these actions and dealing with exceptions. It was challenging to ensure all actions could be completed successfully and to ensure that errors were caught gracefully.