【问题标题】:How to change the name of dictionary in the file when using klepto.archives.file_archive?使用 klepto.archives.file_archive 时如何更改文件中字典的名称?
【发布时间】:2019-10-21 18:52:20
【问题描述】:

运行以下代码后,发现文件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}

【问题讨论】:

    标签: python klepto


    【解决方案1】:

    我是klepto 作者。我不相信这是可能的,目前。但是,如果您确实想要它作为一项功能,请随时请求它(在 klepto 的 GitHub 上)作为增强功能。

    【讨论】:

      猜你喜欢
      • 2011-05-23
      • 2021-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-01
      • 2017-05-29
      • 2018-04-03
      • 1970-01-01
      相关资源
      最近更新 更多