from importlib import import_module


def class_for(full_classname, instantiate=True):
    """

    :param full_classname:
    :param instantiate: True if you wish the found class return an instance.
    :return: Class obj or Class instance.
    """
    segments = full_classname.split('.')
    clsname = segments[-1]
    modname = '.'.join(segments[:-1])
    mod = import_module(modname)
    clz = getattr(mod, clsname)
    if not clz:
        raise Exception("Class not found for " + full_classname)
    if instantiate:
        return clz()
    else:
        return clz