Python for Kids Book: Project 9


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":

Should be


if family_name == "q":

if email_address == "q":

and

if date_of_birth == "q":

respectively. This should be corrected in the second printing. The code samples have the correct code.

5 Responses to Python for Kids Book: Project 9

  1. Gough says:

    Here is one erratum for Python 2 in this book:

    For Python 2 , the following lines in “Test the load Method” section of the book need to be fixed in order to work, i.e. need to change address_book to Addressbook

    >>> from Addressbook import SAVE_FILE_NAME # changed from from address_book import SAVE_FILE_NAME
    >>> from Addressbook import AddressBook, AddressEntry
    # changed from from address_book import AddressBook, AddressEntry

    Otherwise, if fails to work for me in Python 2.

    Thank you very much.

    • brendanscott says:

      Hi Gough

      You’re on page 266 by the looks of it. The line:

      from address_book import SAVE_FILE_NAME

      looks for a file called address_book.py (see numbered item 1 on page 243). If it finds that file, it looks in that file for an object called SAVE_FILE_NAME.

      It seems like you’ve called your file Addressbook.py which is why you needed to change the code.

      Regards

      Brendan

  2. Pingback: Python 4 Kids: Python for Kids Book: Project 9 | techcodesoft

  3. Pingback: Python 4 Kids: Python for Kids Book: Project 9 | techcodesoft

  4. Pingback: Python 4 Kids: Python for Kids Book: Project 9 | techcodesoft

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: