首页 > 解决方案 > 我想从 main_program.py 修改我自己的 my_dicts.py 模块

问题描述

我处于需要不断向我的代码中添加新字典的情况。所以,为了不把它全部塞进一个 .py 文件中,我决定创建模块 my_dicts.py,把它们都写在那里,然后将它导入 main_program.py。

my_dicts.py 看起来像这样:

dict1 = ...
dict2 = ...
dict3 = ...
.
.
.

main_program.py 看起来像这样:

import my_dicts as d

# loading some data.
.
.
.

# running some functions.
.
.
.

# creating a new dictionary with the purpose of adding it to my_dicts.py
new_dictionary = function_to_create_my_new_dictionary(some_data)

我的问题是:如何在不停止 main_program.py 的情况下将 new_dictionary 添加到 my_dicts.py。

标签: pythondictionarymodule

解决方案


推荐阅读