我如何使用jupyter保留对象列表

问题描述 投票:0回答:1

我正在研究Jupyter,并尝试使列表持久化,但腌制只会给我这个错误:

PicklingError                             Traceback (most recent call last)
<ipython-input-34-3ba985598f1e> in <module>
      1 with open("book_data/books.pkl", "wb") as cf:
----> 2    pickle.dump(book_list, cf)

PicklingError: Can't pickle <class '__main__.book'>: it's not the same object as __main__.book

我尝试使用莳萝来保存会话,但它给了我这个错误:

RecursionError                            Traceback (most recent call last)
<ipython-input-33-5011bc09ef45> in <module>
      1 import dill
----> 2 dill.dump_session('Data_Gathering.db')
python-3.x jupyter-notebook persistence pickle dill
1个回答
0
投票

我是dill作者。如果您只想腌制对象列表,则可以尝试]

with open("book_data/books.pkl", "wb") as cf:
    dill.dump(book_list, cf)

dill可以使整个会话腌制,但是从木星笔记本中进行腌制会有些困难,因此,通常,腌制您感兴趣的对象会更容易。

© www.soinside.com 2019 - 2024. All rights reserved.