get a class or function by name

def get_attr(name):
    """
    get a class or function by name
    """
    i = name.rfind('.')
    cls = str(name[i+1:])
    module = str(name[:i])

    mod = __import__(module, fromlist=[cls])
    return getattr(mod, cls)