Skip to content

Instantly share code, notes, and snippets.

@workze
Last active April 18, 2020 06:47
Show Gist options
  • Select an option

  • Save workze/3373d4e2566908427ceb65b2f4e3f0b4 to your computer and use it in GitHub Desktop.

Select an option

Save workze/3373d4e2566908427ceb65b2f4e3f0b4 to your computer and use it in GitHub Desktop.
python reload re-import module
import importlib
importlib.reload(some_module)
reload() 只能接模块对象,如果要接'str', 需要先 import_module()
包下可以是模块;也可以是__init__里import进来的对象。
如果是from xxx import A,要热加载A,必须热加载xxx。
如何根据A找到xxx?
获取cls对象,cls.__module__
也可以直接从sys.modules获取模块实例,然后reload
step
A属性
a.py
A属性
app.py 使用step.A获取A. 必须reload(step)
获取模块的文件路径 module_a.__file__ os.path.abspath(module_a.__file__)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment