def import_from_string(val, setting_name):
try:<EOL><INDENT>parts = val.split('<STR_LIT:.>')<EOL>module_path, class_name = '<STR_LIT:.>'.join(parts[:-<NUM_LIT:1>]), parts[-<NUM_LIT:1>]<EOL>module = importlib.import_module(module_path)<EOL>return getattr(module, class_name)<EOL><DEDENT>except ImportError as e:<EOL><INDENT>msg = "<STR_LIT>" % (val, setting_name,<EOL>e.__class__.__name__, e)<EOL>raise ImportError(msg)<EOL><DEDENT>
Attempt to import a class from a string representation.