Python for Kids Book: Project 9
September 7, 2015 5 Comments
In these posts I outline the contents of each project in my book Python For Kids For Dummies. If you have questions or comments about the project listed in the title post them here. Any improvements will also be listed here.
What’s in Project 9 (Address Book)
While Project 6 introduced the concept of objects and showed how even a lowly string is actually an object, Project 9 is about how you can make your own objects using the class keyword. Project 9 uses classes to implement a simple address book application. I discuss the difference between a class and an instance of the class and the importance of having a reference variable (self) so that an instance can refer to itself. You learn about constructor functions and how to override a method (__repr__) to make print statements work properly on your custom method.
Since having an address book is not much use if you can’t save and update it, I also introduce the pickle module. It is used to store general Python objects (if they’re hashable!). The address book is given save and load functions as well as a rudimentary user interface.
Improvements (1st printing):
On page 278 in the add_entry method, the second through fourth occurrences of the code
if first_name == "q":
if family_name == "q": if email_address == "q":
if date_of_birth == "q":
respectively. This should be corrected in the second printing. The code samples have the correct code.