def for_name(fq_name, recursive=False):
fq_name = str(fq_name)<EOL>module_name = __name__<EOL>short_name = fq_name<EOL>if fq_name.rfind("<STR_LIT:.>") >= <NUM_LIT:0>:<EOL><INDENT>(module_name, short_name) = (fq_name[:fq_name.rfind("<STR_LIT:.>")],<EOL>fq_name[fq_name.rfind("<STR_LIT:.>") + <NUM_LIT:1>:])<EOL><DEDENT>try:<EOL><INDENT>result = __import__(module_name, None, None, [short_name])<EOL>return result.__dict__[short_name]<EOL><DEDENT>except KeyError:<EOL><INDENT>if recursive:<EOL><INDENT>raise<EOL><DEDENT>else:<EOL><INDENT>raise ImportError("<STR_LIT>" % (<EOL>short_name, module_name))<EOL><DEDENT><DEDENT>except ImportError as e:<EOL><INDENT>try:<EOL><INDENT>module = for_name(module_name, recursive=True)<EOL>if hasattr(module, short_name):<EOL><INDENT>return getattr(module, short_name)<EOL><DEDENT>else:<EOL><INDENT>raise KeyError()<EOL><DEDENT><DEDENT>except KeyError:<EOL><INDENT>raise ImportError("<STR_LIT>" % (<EOL>short_name, module_name))<EOL><DEDENT>except ImportError:<EOL><INDENT>pass<EOL><DEDENT>raise<EOL><DEDENT>
Find class/function/method specified by its fully qualified name.

    Fully qualified can be specified as:
      * <module_name>.<class_name>
      * <module_name>.<function_name>
      * <module_name>.<class_name>.<method_name> (an unbound method will be
        returned in this case).

    for_name works by doing __import__ for <module_name>, and looks for
    <class_name>/<function_name> in module's __dict__/attrs. If fully qualified
    name doesn't contain '.', the current module will be used.

    Args:
      fq_name: fully qualified name of something to find

    Returns:
      class object.

    Raises:
      ImportError: when specified module could not be loaded or the class
      was not found in the module.