Mostly this is a Python question, but it can be helpful to see working examples. Just like topology isn't strictly a Blender specific topic yet we still cover it sometimes. This reimport / and local imports topic is not necessarily obvious in a Blender add-on context.
If you have a folder called 'SomeAddon' and it contains the following files.
SomeAddon
Ͱ __init__.py
Ͱ resources.py
And you want to import a few functions from resources.py
into __init__.py
, then you do
from .resources import (function1, function2, function3)
This will work once, but when you go to reload python F8 - as you will most likely do a lot during development - the changes you make to the functions (function1, function2, function3)
will not be pulled in - globals()
will still contain the cached versions of the old functions.
You can control what your add-on does during the reload event (triggered by F8). Most add-ons have some form of explicit reload of their modules. What tends to work is this (or something similar):
if 'resources' in globals():
importlib.reload(resources)
from .resources import (function1, function2, function3)
The first time you enable the add-on, resources
is hoisted into the globals for this module (your add-on). When you hit F8 resources
is already present and to update it you need to use importlib
's reload function.
__init__.py
file inside a folder to make it recognized as a Python module. $\endgroup$