Message415341
For the following code piece:
```
import pickle
class Child:
def __init__(self, field):
self.field = field
class Parent:
child = Child(0.5)
if __name__ == '__main__':
i = input()
if i == 'd':
parent = Parent()
parent.child.field = 0.6
pickle.dump(parent, open('test.pkl', 'wb+'))
else:
parent = pickle.load(open('test.pkl', 'rb'))
print(parent.child.field)
```
After dumping, when we load the file throught `pickles.load`, `parent.child.field` is 0.5, and is not 0.6, which we intend it to be.
However, after removing the line `child = Child(0.5)` and moving it to `__init__(self)` of `Parent`, everything works fine.
I'm not sure whether this is indeed an issue. If not, sorry for take your time. |
|
Date |
User |
Action |
Args |
2022-03-16 14:24:35 | jeffersonqin | set | recipients:
+ jeffersonqin |
2022-03-16 14:24:35 | jeffersonqin | set | messageid: <1647440675.94.0.131191569547.issue47034@roundup.psfhosted.org> |
2022-03-16 14:24:35 | jeffersonqin | link | issue47034 messages |
2022-03-16 14:24:35 | jeffersonqin | create | |
|