# PetsDict Example # test3.py module # Populate classes from files, then lookup pet info by pet name. # Each pet has a social media page, so a list of followers is # included for each pet. from pet import Pet # Create empty dictionary pets_dict = { } # Open input file fin1 = open("pets.txt", "r") # Throw away first line fin1.readline( ) for line in fin1: fields = line.split(",") p = Pet(fields[0], fields[1], fields[2], \ fields[3], fields[4], bool(fields[5].strip( ))) pets_dict[fields[3]] = p print(pets_dict) fin2 = open("followers.txt", "r") for line in fin2: fields = line.strip( ).split(",") name = fields.pop(0) for f in fields: pets_dict[name].add_follower(f) for k in pets_dict.keys( ): print(k, ":", pets_dict[k].followers) print( ) search_name = input("Enter pet name: ") if search_name in pets_dict: p = pets_dict[search_name] print("Animal type: ", p.animal_type) print("Breed: ", p.breed) print("Gender: ", p.gender) print("Pet name: ", p.name) print("Pet owner: ", p.owner) print("Is pet vaccinated: ", p.is_vaccinated) print("Followers: ", p.followers) else: print("Pet not in dictionary")