Pickle linked objects

后端 未结 3 1001
情歌与酒
情歌与酒 2021-01-02 01:51

I want to pickle an object and a second object that references the first. When I naively pickle/unpickle the two objects, the reference becomes a copy. How do I preserve t

3条回答
  •  自闭症患者
    2021-01-02 02:07

    Well, can you do:

    bar2 = pickle.load(f)
    foo2 = bar2.foo_ref
    

    Let pickle handle the link for you.

提交回复
热议问题