【问题标题】:How can i create a dynamic dictionary in a Python script sharing its contents with another script? [closed]如何在 Python 脚本中创建动态字典,与另一个脚本共享其内容? [关闭]
【发布时间】:2012-07-25 04:36:17
【问题描述】:

我有一个Python字典如下

dictvvalue={'a':'1','b':'2','c':{'d':'5','e':'6'}}

我的目的是保存这个 Python 字典以供另一个 Python 脚本使用。

我必须将此字典作为字典而不是字符串加载到其他脚本中。

请帮忙

谢谢

【问题讨论】:

标签: python python-2.6


【解决方案1】:

正如 Generic 所暗示的,您必须将其编码为字节串,然后才能将其持久化,然后在读入时对其进行解码。在 Python 中执行此操作的常用方法是酸洗(通过 @987654321 @/cPickle)、JSON(通过 json)或 YAML(通过 PyYAML)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-02
    • 2021-12-20
    • 1970-01-01
    • 1970-01-01
    • 2012-02-13
    • 2021-11-13
    • 1970-01-01
    相关资源
    最近更新 更多