Created
June 8, 2018 17:12
-
-
Save jjconti/3705211df71c9e6e0560b80ba35f0b8f to your computer and use it in GitHub Desktop.
Does pickle store methods?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> class A(object): | |
... pass | |
... | |
>>> import pickle | |
>>> from cStringIO import StringIO | |
>>> src = StringIO() | |
>>> p = pickle.Pickler(src) | |
>>> p.dump(A()) | |
>>> datastream = src.getvalue() | |
>>> dst = StringIO(datastream) | |
>>> up = pickle.Unpickler(dst) | |
>>> class A(object): | |
... def __init__(self): | |
... self.a = 1 | |
... def hi(self): | |
... return 'hi' | |
... | |
>>> obj = up.load() | |
>>> obj.hi() | |
'hi' | |
>>> obj.a | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
AttributeError: 'A' object has no attribute 'a' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment