我们从Python开源项目中,提取了以下48个代码示例,用于说明如何使用setuptools.py26compat.import_module()。
def _parse_attr(cls, value): """Represents value as a module attribute. Examples: attr: package.attr attr: package.module.attr :param str value: :rtype: str """ attr_directive = 'attr:' if not value.startswith(attr_directive): return value attrs_path = value.replace(attr_directive, '').strip().split('.') attr_name = attrs_path.pop() module_name = '.'.join(attrs_path) module_name = module_name or '__init__' sys.path.insert(0, os.getcwd()) try: module = import_module(module_name) value = getattr(module, attr_name) finally: sys.path = sys.path[1:] return value