I was using an api -- smartsheet-python-sdk that was running fine when executed from the source code. However, when I went to package using PyInstaller I was getting an error because PyInstaller couldn't find the necessary modules. In the smartsheet library it is using importlib.import_module to import modules from the library.
def __getattr__(self, name):
"""
Handle sub-class instantiation.
Args:
name (str): Name of smartsheet to instantiate.
Returns:
Instance of named class.
"""
try:
# api class first
class_ = getattr(importlib.import_module(
__package__ + '.' + name.lower()), name)
return class_(self)
except ImportError:
# model class next:
try:
class_ = getattr(importlib.import_module(
name.lower()), name)
return class_()
except ImportError:
self._log.error(
'ImportError! Could not load api or model class %s', name)
return name
Is there any objective benefit to using something like this when it is only importing modules from its own library as opposed to just adding Import Statements to known modules?