我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用types.ModuleType.__init__()。
def modulify(cls): """Replace the class' module with an instance of the class. Useful for creating modules with __getattr__, descriptors, etc. """ dct = dict(vars(cls)) # Make sure __init__ is defined, to avoid falling back to # ModuleType.__init__ (which requires an argument) dct.setdefault('__init__', object.__init__) mod = type(cls.__name__, (ModuleType,), dct) sys.modules[cls.__module__] = mod()
def __init__(self, name, attrmap, proxy=None): ModuleType.__init__(self, name) self.__attrmap = attrmap self.__proxy = proxy self.__log = logging.getLogger(name)
def __init__(self, name, system_import): ModuleType.__init__(self, name) self._system_import = system_import self._modules_to_patch = {}