Sep-14-2019, 05:41 PM
After talking with some folks in another forum, best practice might be not to store the class object at all, but rather to store the attributes of those objects to a list or dictionary and then recreate them later. But I didn't understand their explanation of how to do that. This was the example they gave me:
class Dog: def __init__(self, name, color, age): self.name = name self.color = color self.age = age def bark(): print("Woof") def eat_homework(file): with open(file, "w") as homework: homework.write("") doggo = Dog("Spot", "Black and White", 2) #Instead of saving Dog object we can just save the attributes #doggo.name, doggo.color, doggo.age --- that's all the info we need to #recreate our object. #in this case, all you'd have to write to a file is: #["Spot", "Black and White", 2]Lines 11-12 don't appear to be writing anything to file.