New question: "How to create a module or variable with the name from a string?"
import sys import os import importlib dir = os.path.dirname(bpy.data.filepath) dir = os.path.join(dir, "Scripts") # The script must be located in that folder if not dir in sys.path: sys.path.append(dir) ''' #---------- Method 1 ---------- # There is no problem if there is no 'for', but I will have many modules, so I can't do these. main = importlib.import_module('main') MyModule = importlib.import_module('MyModule')''' #---------- Method 2 ---------- module_names = ( 'main', 'MyModule') for name in module_names: value = importlib.import_module(name) create_var_by_str(name, value) # FIXME: Here is my problem, I want to create a variable named of the # value of 'name', and assign to it the value of 'value'.