19 lines
622 B
Python
19 lines
622 B
Python
from importlib import import_module
|
|
|
|
|
|
class Instance:
|
|
|
|
@staticmethod
|
|
def get_instance(module_name, class_name):
|
|
try:
|
|
module = import_module(module_name)
|
|
class_obj = getattr(module, class_name)
|
|
instance = class_obj()
|
|
return instance
|
|
except ImportError:
|
|
print("Модуль отсутствует, но единороги — нет 🦄")
|
|
return None
|
|
except AttributeError:
|
|
print("Класс не найден, возможно, он отдыхает с пинтой пива 🍺")
|
|
return None
|