簡體   English   中英

使用klepto.archives.file_archive時如何更改文件中的字典名稱?

[英]How to change the name of dictionary in the file when using klepto.archives.file_archive?

運行以下代碼后,我發現文件memo.py中的字典名稱是memo 我想更改該文件中字典的名稱。 有誰知道怎么做?

>>> init = {'y': 2, 'x': 1, 'z': 3}
>>> import klepto
>>> cache = klepto.archives.file_archive('memo', init, serialized=False)
>>> cache        
{'y': 2, 'x': 1, 'z': 3}
>>>
>>> # dump dictionary to the file 'memo.py'
>>> cache.dump() 
>>> 
>>> # import from 'memo.py'
>>> from memo import memo
>>> print memo
{'y': 2, 'x': 1, 'z': 3}
>>> from memo import memo
>>> print memo
{'y': 2, 'x': 1, 'z': 3}

我是klepto作者。 目前我不相信這是可能的。 但是,如果你確實想要它作為一個功能,那么隨意請求(在klepto的GitHub上)作為增強功能。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM