【发布时间】: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}
【问题讨论】: