Sep-14-2019, 06:16 PM
It appears they borked their example. From the comment, it looks like that was supposed to be a list, using your attributes, not an empty string. Besides that, neither method has a self argument, so the example would result in an error. And they don't even attempt to show reading, as opposed to writing. What forum did you go to? Generally, it's seen as polite to inform both forums of each other to prevent duplicate work.
As for your problem - I recommend not writing a straight list to a file. Create a dict/list (either is fine; I would probably prefer a dict because I think it's more human-readable, assuming file size / performance are not at issue), then use the json module to dump that Python object to disk as JSON. You can then use the same module to read that back from a file and then you can build your class from whatever you read from disk.
As for your problem - I recommend not writing a straight list to a file. Create a dict/list (either is fine; I would probably prefer a dict because I think it's more human-readable, assuming file size / performance are not at issue), then use the json module to dump that Python object to disk as JSON. You can then use the same module to read that back from a file and then you can build your class from whatever you read from disk.