from __future__ import division, print_function
import importlib
[docs]
def print_warning(msg):
"""Print Warning in yellow color.
Parameters
----------
msg : str
String to print.
"""
print("\033[93m" + msg + "\033[0m")
[docs]
def load_class(full_class_string):
"""
dynamically load a class from a string
Parameters
----------
full_class_string : str
The full class string to the given python clas.
Example:
my_project.my_module.my_class
Returns
-------
python class
PYthon class defined by the 'full_class_string'
"""
class_data = full_class_string.split(".")
module_path = ".".join(class_data[:-1])
class_str = class_data[-1]
module = importlib.import_module(module_path)
# Finally, we retrieve the Class
return getattr(module, class_str)