import pickle
class Foo:
x = "Cannot be pickled"
def __init__(self, a):
self.a = a
hello = Foo(a = 10)
with open("foo.pickle", "wb") as f:
pickle.dump(hello, f)
with open("foo.pickle", "rb") as f:
world = pickle.load(f)
print(f"world.a: {world.a}, world.x: {world.x}")
Output:
world.a: 10, world.x: Cannot be pickled
In the above code pickling and unpickling of class variables works fine for me. But in this stackoverflow link Pickle both class variables and instance variables? it says we can't pickle class variables and alternate solution are given using dill module.
Can anyone explain why its working for me?