fix dynamic module loading python3
authorGP Orcullo <kinsamanka@gmail.com>
Fri, 28 Oct 2022 14:58:25 +0800
branchpython3
changeset 3757 814595c0ea16
parent 3756 8db203310f68
child 3758 bc71b19b45ff
fix dynamic module loading
connectors/__init__.py
targets/__init__.py
--- a/connectors/__init__.py	Fri Oct 28 14:56:07 2022 +0800
+++ b/connectors/__init__.py	Fri Oct 28 14:58:25 2022 +0800
@@ -27,6 +27,7 @@
 
 
 import os
+import importlib
 from os import listdir, path
 from connectors.ConnectorBase import ConnectorBase
 
@@ -34,7 +35,8 @@
 
 
 def _GetLocalConnectorClassFactory(name):
-    return lambda: getattr(__import__(name, globals(), locals()), name + "_connector_factory")
+    return lambda: getattr(importlib.import_module(f"connectors.{name}"),
+                           f"{name}_connector_factory")
 
 
 connectors = {name: _GetLocalConnectorClassFactory(name)
@@ -53,7 +55,7 @@
         per_URI_connectors = {}
         schemes = []
         for con_name in connectors_packages:
-            module = __import__(con_name + '_dialog', globals(), locals())
+            module = importlib.import_module(f"connectors.{con_name}_dialog")
 
             for scheme in module.Schemes:
                 per_URI_connectors[scheme] = getattr(module, con_name + '_dialog')
--- a/targets/__init__.py	Fri Oct 28 14:56:07 2022 +0800
+++ b/targets/__init__.py	Fri Oct 28 14:58:25 2022 +0800
@@ -35,15 +35,15 @@
 """
 
 
-
 from os import listdir, path
 import util.paths as paths
+import importlib
 
 _base_path = paths.AbsDir(__file__)
 
 
 def _GetLocalTargetClassFactory(name):
-    return lambda: getattr(__import__(name, globals(), locals()), name+"_target")
+    return lambda: getattr(importlib.import_module(f"targets.{name}"), f"{name}_target")
 
 
 targets = dict([(name, {"xsd":   path.join(_base_path, name, "XSD"),