def module_attribute(dotpath, default=None, safe=False):
    if dotpath:
        bits = str(dotpath).split(':')
        try:
            if len(bits) == 2:
                attr = bits[1]
                module_name = bits[0]
            else:
                bits = bits[0].split('.')
                if len(bits) > 1:
                    attr = bits[-1]
                    module_name = '.'.join(bits[:-1])
                else:
                    raise ValueError('Could not find attribute in %s'
                                     % dotpath)

            module = import_module(module_name)
            return getattr(module, attr)
        except Exception:
            if not safe:
                raise
            return default
    else:
        if not safe:
            raise ImportError
        return default
Load an attribute from a module.
dataset/ETHPy150Open quantmind/pulsar/pulsar/utils/importer.py/module_attribute