I'm writing a class that has an attribute of numpy array type. Since I'd like it to be read-only, I set its WRITABLE flag to be false:
import numpy as np
class MyClass:
def __init__(self):
self.my_array = np.zeros(5)
self.my_array.setflags(write=False)
After doing some other stuff, I dump MyClass into a pickle file:
pickle.dump(self, writer)
Later, I load it using x = pickle.load(reader)
, but then the WRITABLE flag is true.
How can I make the pickle dump to preserve the numpy array WRITABLE flag?