tg_bot/halpers/Instance.py
2024-12-22 13:49:31 +03:00

19 lines
622 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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