from family import Person, Baby, Teenager, Adult, Senior from family import load_from_file, save_to_file my_family = load_from_file("my_family.json") marc = my_family[0] parents = marc.who_are_my_parents(my_family) print "My parents are %s" % (", ".join(map(str, parents))) save_to_file(my_family, "my_family.json")
from family import Person, Baby, Teenager, Adult, Senior from family import load_from_file, save_to_file # new adult a = Adult(0, "Abigail", [10, 24, 1990], "Female", "Blue") c = Adult(1, "Carl", [7, 15, 1992], "Male", "Brown") d = Senior(2, "Darlene", [3, 4, 1968], "Female", "Brown") list_of_instances = [a, c, d] save_to_file(list_of_instances, "my_family.json") my_family = load_from_file("my_family.json") print "I have %d members in my family" % len(my_family) print my_family # new baby! b = Baby(3, "Tony", [7, 4, 2015], "Male", "Green") b.last_name = "Foto" my_family.append(b) print my_family save_to_file(my_family, "my_family.json")
from family import Person, Baby, Teenager, Adult, Senior from family import load_from_file, save_to_file my_family = load_from_file("my_family.json") marc = my_family[0] vanessa = my_family[1] boby = my_family[2] vanessa.adopt_child(boby) marc.adopt_child(boby) monica = vanessa.has_child_with(marc, 5, "Monica", [5, 6, 2016], "Female", "Blue") print "Vanessa has %d children" % (len(vanessa.children)) save_to_file(my_family)
from family import Person, Baby, Teenager, Adult, Senior from family import load_from_file, save_to_file my_family_contents = load_from_file("my_family.json") #my_family_contents = json.dumps([{"first_name": 'Rona', "last_name": 'Chong', "genre": 'Female', "date_of_birth": [12, 24, 1993], "eyes_color": 'Brown', "id": 20}]) print my_family_contents save_to_file(my_family_contents, "my_family.json")