How can I get the module object/namespace for an already-loaded script datablock, given only the name/ID/path of the text datablock?
.as_module() doesn't do this, because D.texts[0].as_module() is D.texts[0].as_module() == False— as_module() returns a new object and namespace, so it can't be used to alter or unregister the already-imported definitions. It also doesn't set __file__ correctly.
Basically, I'm looking for something like addon_utils.modules(), except with no fake modules, and if it also included all user scripts from which a type has been registered.
globals()tobpy.ModuleName.__dict__from inside each module/script, so I can callbpy.ModuleName.unregister()later. The idea is to be able to get the original namespace for arbitrary modules without requiring the modules to register themselves in that way.as_module()doesn't work because it just creates a new module withexec. I would expect there to be some way to getas_module() is as_module()because modules are usually singletons shared across multiple import statements, and the types are clearly kept around. – Will Chen Jun 08 '21 at 21:35addon_utils.modules(), except with no fake modules, and if it also included all user scripts that had been run— Although, how such arbitrary and potentially conflicting data would be best sorted and discarded may be messy. – Will Chen Jun 08 '21 at 21:37addon_utills.modules()?? – batFINGER Jun 09 '21 at 13:54as_module()method returns a new module like object using the code in the texblock How to make your own module like object instead is well covered on stackoverlow. – batFINGER Jun 09 '21 at 14:05