How To Save Objects In Python Without Using Pickle?
I want to save a object in a file so i can use it later (after the program closes). I tried to use pickle, but looks like it doesn't like my object :D Traceback (most recent call l
Solution 1:
The easiest solution is going to be to define your class in such a way that it's pickle-able. The error message suggests that some of your class's attributes can't be pickled because they don't have globally-scoped names.
If you want to save an object that's not pickleable, you'll need to write your own logic to serialize and deserialize it. It's impossible to give specific advice on this without seeing the object, but the general idea is that you need to figure out how to represent your object's state as something that you CAN pickle (like a series of simple string/int attributes) and then write a function that will reconstitute your object from that data.
Post a Comment for "How To Save Objects In Python Without Using Pickle?"