Try something like this:
def import_obj(path): path_parts = path.split(".") obj = __import__(".".join(path_parts[:-1])) path_remainder = list(reversed(path_parts[1:])) while path_remainder: obj = getattr(obj, path_remainder.pop()) return obj
This will work for anything that can be getattr from a module, for example. module level functions, constants, etc.
rfw source share