[英]Blender Python - Force reload of module while importing all its classes
我在 Python/Blender 中開發,這里有兩個需求:
目前我正在這樣做(在__init__.py
中):
from importlib import reload
from .MyPlugin import *
reload(MyPlugin)
classes = [ClassA, ClassB, ClassC]
# register each class, not shown here
但是reload(MyPlugin)
行會導致錯誤:“MyPlugin is not defined”。
最初我嘗試重新加載每個類,但它引發了一個錯誤, reload
需要一個模塊。
一些同事幫我回答了,最終在__init__.py
起作用的是:
from importlib import reload
if "MyModule" in locals():
reload(MyModule)
else:
import MyModule
from .MyModule import *
這在這里有詳細說明: https : //blenderartists.org/t/how-to-reload-add-on-code/1202715/2
這適用於舊版本(使用 2.79 測試)首先重新啟動!
del sys.modules['foo']
from foo import *
對不起,答案對我來說不清楚。 我有一些我喜歡在外部編輯的腳本。 說 script1, script2, ...
import script1, script2, ...
這些腳本運行良好,但編輯后應重新加載。 執行此操作的代碼是什么?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.