I am creating a series of object instances, the attributes of which i save and load using their __dict__
attribute. I would like to keep some attributes outside of __dict__
, simply because i do not want them to be saved or loaded.
More specifically:
I created a parent object merely holding a list of children objects. Children objects' __dict__
is saved to file and loaded later on to instantiate them again. I want the children objects to have a reference to the parent, but i do not want that reference to be saved to, nor loaded from file, as it would not make sense.
Is there any syntax that would exclude the attribute from __dict__
?
PS: many answers suggest using pickle, i am currently using json to keep data human readable.
Add some prefix for attributes you don't want to save and exclude them while saving.
This approach won't work and so is not going to solve your problem. You should instead extend your framework to allow you to specify which attributes were to be omitted from the save/load.
However, it seems odd that you aren't using one of the built in persistence techniques, e.g. pickle, that already offer such features.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With