from family import Person, Baby, Teenager, Adult, Senior a = Adult(1, "Marc", [12, 24, 1980], "Male", "Blue") a.last_name = "Zuckerberg" b = Baby(3, "Steeve", [7, 4, 2015], "Male", "Green") b.last_name = "Rod" if a.can_vote(): print "%s can vote" % (a) if b.can_vote(): print "%s can vote" % (b) if a.is_young(): print "%s is young" % (a) if b.need_help(): print "%s needs help" % (b)
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") #print "I have %d members in my family" % len(my_family) b=[0,1] # new baby! b[0] = Person(3, "Tony", [7, 4, 2015], "Male", "Green") b[0].last_name = "Rod" b[1] = Baby(3, "jjjj", [7, 4, 2015], "Male", "Green") b[1].last_name = "Foto" #my_family.append(b) save_to_file(b, "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") print "I have %d members in my family" % len(my_family) # new baby! b = Baby(3, "Tony", [7, 4, 2015], "Male", "Green") b.last_name = "Foto" my_family.append(b) # 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 Tony = Baby(3, "Tony", [7, 4, 2015], "Male", "Green") Tony.last_name = "Foto" print Tony.json() Tony_json = {'last_name': "Foto", 'first_name': "Tony", 'genre': "Male", 'date_of_birth': [7, 4, 2015], 'eyes_color': "Brown", 'ide': 3} Tony.load_from_json(Tony_json) print Tony.last_name