【发布时间】:2012-09-11 20:14:22
【问题描述】:
在我的应用程序中,我使用包 example 中的模块,称为 examplemod。
我的应用:
from example import examplemod
examplemod.do_stuff()
它像这样在example 中导入另一个模块。
examplemod.py:
from example import config
# uses config
# then does stuff
config 使用常量。
config.py:
CONSTANT = "Unfortunate value"
当我在我的应用程序中使用examplemod(将其设置为CONSTANT = "Better value")时,我想覆盖这个常量,并且我不想修改底层模块,所以我不必维护我的自己的包。我该怎么做?
【问题讨论】:
-
我可能是错的,但我认为您可以在导入变量后为其赋值。
标签: python module python-import