简体   繁体   English

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

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

After running the following code, I found that the name of the dictionary in file memo.py is memo . 运行以下代码后,我发现文件memo.py中的字典名称是memo I want to change the name of the dictionary in that file. 我想更改该文件中字典的名称。 Do anyone know how to do it? 有谁知道怎么做?

>>> 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}

I'm the klepto author. 我是klepto作者。 I don't believe it's possible, currently. 目前我不相信这是可能的。 However, if you do want it as a feature, then feel free to request it (on klepto 's GitHub) as an enhancement. 但是,如果你确实想要它作为一个功能,那么随意请求(在klepto的GitHub上)作为增强功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM