2

Ok, so I have the following question:

I have the following: x.py:

from y import aFunc

y.py:

from z import aDict

Now, x runs on a run,sleep,repeat schedule. It then calls aFunc on certain files. aFunc uses the values in aDict and then returns.

aDict is in a python module that is managed by a user in the econ department. I understand that import is called once and then cached. Even if I was to put the import statement inside aFunc it'll still be imported only once and then cached (please correct me if I'm wrong).

But I want to be able to pick up any changes to aDict on the fly, in other words, I'd like to re-import z.aDict every time x called y.aFunc

Any advice will be much appreciated!

4

2 回答 2

4

您可以使用重新加载,但您不能使用

from z import aDict

您可以执行以下操作:

reload(z)
#do something with z.aDict here
于 2013-07-25T17:13:24.950 回答
0

看来我找到了答案。它与 reload(aDict) 似乎使事情保持新鲜......但希望这对其他人有所帮助!

编辑:哎呀!reload 只能取模块。所以我最终做的是导入整个模块,然后在我的代码中添加 z.aDict 前缀。

从 python 文档重新加载

于 2013-07-25T17:12:21.070 回答