When I instantiate a specific class that I wrote, I give it a name and several properties as arguments to __init__ . Given that the name has passed, my __init__ tries to find the file on disk that applies to that name, and instead of processing the rest of the arguments passed, it reads all the data from the file. And if the file is not found, arguments are used instead.
Now I wonder if I wanted to use pickle to store the entire object instead of using my own routines to write files, how would I upload? I canβt expand my object inside __init__ because the object is already created, right?
One of my ideas is to write a class method that I will use to create an instance instead, which returns an unpainted object if it is stored on disk, otherwise it will create a new object with the parameters passed.
Another idea is to use __new__ instead of a class method that will return an object, however I don't know if this is the intended use of __new__ .
Are these ideas good or is there a better way to achieve this?
source share