I have looked through the information that the Python documentation for pickle gives, but I’m still a little confused. What would be some sample code that would write a new file and then use pickle to dump a dictionary into it?
I have looked through the information that the Python documentation for pickle gives, but
Share
Try this:
There’s nothing about the above solution that is specific to a
dictobject. This same approach will will work for many Python objects, including instances of arbitrary classes and arbitrarily complex nestings of data structures. For example, replacing the second line with these lines:will produce a result of
Trueas well.Some objects can’t be pickled due to their very nature. For example, it doesn’t make sense to pickle a structure containing a handle to an open file.