是否可以在Python中深入複製擱置對象?當我嘗試對其進行深度複製時,出現以下錯誤:如何深入複製在Python中擱置對象
import shelve,copy
input = shelve.open("test.dict", writeback=True)
input.update({"key1": 1, "key2": 2})
newinput = copy.deepcopy(input)
>> object.__new__(DB) is not safe, use DB.__new__()
這是否意味着貨架不可複製?
編輯:也許這可能會更好,如果我詳細說明我的問題更多:我保留一個大字典作爲擱置對象,並且我想保存整個擱置對象(=到目前爲止我生成的所有鍵,val對)到一個單獨的文件,而我不斷添加新的項目,以原始字典。
也許我可以先同步擱置並明確地將擱置文件複製到磁盤上,但我不喜歡這種方法。
謝謝,它工作正常! – user2779485