Add "import method from string" in new utils file

This commit is contained in:
Mathieu B 2021-07-26 20:55:36 +02:00
parent be01ac4b27
commit 708ea65163

12
utils/utils.py Normal file
View File

@ -0,0 +1,12 @@
import importlib
def import_method_from_string(file, method_name):
"""
Add the posibility to import method dynamically using a string like "intents.daily.date_and_time.intent" as file and
"what_time_is_it" as method_name
"""
mod = importlib.import_module(file)
met = getattr(mod, method_name)
return met