[英]Blender Python - Force reload of module while importing all its classes
I am developing in Python/Blender, and have two needs here:我在 Python/Blender 中开发,这里有两个需求:
Currently I am doing this (in __init__.py
):目前我正在这样做(在
__init__.py
中):
from importlib import reload
from .MyPlugin import *
reload(MyPlugin)
classes = [ClassA, ClassB, ClassC]
# register each class, not shown here
However the reload(MyPlugin)
line causes an error: "MyPlugin is not defined".但是
reload(MyPlugin)
行会导致错误:“MyPlugin is not defined”。
Originally I tried reloading each of the classes instead, but it raised an error that reload
expects a module.最初我尝试重新加载每个类,但它引发了一个错误,
reload
需要一个模块。
Some colleagues helped me with an answer, what ended up working was this in __init__.py
:一些同事帮我回答了,最终在
__init__.py
起作用的是:
from importlib import reload
if "MyModule" in locals():
reload(MyModule)
else:
import MyModule
from .MyModule import *
This is detailed here: https://blenderartists.org/t/how-to-reload-add-on-code/1202715/2这在这里有详细说明: https : //blenderartists.org/t/how-to-reload-add-on-code/1202715/2
this works with older Version (tested with 2.79) Restart first!这适用于旧版本(使用 2.79 测试)首先重新启动!
del sys.modules['foo']
from foo import *
Sorry, the answers are not clear to me.对不起,答案对我来说不清楚。 I have some scripts I like to edit externally.
我有一些我喜欢在外部编辑的脚本。 Say script1, script2, ... With
说 script1, script2, ...
import script1, script2, ...
those scripts are working well but after editing they should be reloaded.这些脚本运行良好,但编辑后应重新加载。 What is the code to do this?
执行此操作的代码是什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.