MCPcopy Create free account
hub / github.com/ForensicArtifacts/artifacts-kb / _ImportPythonModule

Method _ImportPythonModule

utils/dependencies.py:271–290  ·  view source on GitHub ↗

Imports a Python module. Args: module_name (str): name of the module. Returns: module: Python module or None if the module cannot be imported.

(self, module_name)

Source from the content-addressed store, hash-verified

269 return True, f"{module_name:s} version: {module_version!s}"
270
271 def _ImportPythonModule(self, module_name):
272 """Imports a Python module.
273
274 Args:
275 module_name (str): name of the module.
276
277 Returns:
278 module: Python module or None if the module cannot be imported.
279 """
280 try:
281 module_object = list(map(__import__, [module_name]))[0]
282 except ImportError:
283 return None
284
285 # If the module name contains dots get the upper most module object.
286 if "." in module_name:
287 for submodule_name in module_name.split(".")[1:]:
288 module_object = getattr(module_object, submodule_name, None)
289
290 return module_object
291
292 def _PrintCheckDependencyStatus(
293 self, dependency, result, status_message, verbose_output=True

Callers 1

_CheckPythonModuleMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected