当前位置: 首页>>代码示例>>Python>>正文


Python ModuleType.__name__方法代码示例

本文整理汇总了Python中types.ModuleType.__name__方法的典型用法代码示例。如果您正苦于以下问题:Python ModuleType.__name__方法的具体用法?Python ModuleType.__name__怎么用?Python ModuleType.__name__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在types.ModuleType的用法示例。


在下文中一共展示了ModuleType.__name__方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __name__ [as 别名]
def main(module=None):

    # Pygame won't run from a normal virtualenv copy of Python on a Mac
    if not _check_python_ok_for_pygame():
        _substitute_full_framework_python()

    if not module:
        parser = OptionParser()
        options, args = parser.parse_args()

        if len(args) != 1:
            parser.error("You must specify which module to run.")

        if __debug__:
            warnings.simplefilter('default', DeprecationWarning)

        path = args[0]
    else:
        path = module
    with open(path) as f:
        src = f.read()

    code = compile(src, os.path.basename(path), 'exec', dont_inherit=True)

    loaders.set_root(path)

    pygame.display.set_mode((100, 100), DISPLAY_FLAGS)
    name, _ = os.path.splitext(os.path.basename(path))
    mod = ModuleType(name)
    mod.__file__ = path
    mod.__name__ = name
    mod.__dict__.update(builtins.__dict__)
    sys.modules[name] = mod
    exec(code, mod.__dict__)
    Juego(mod).run()
开发者ID:yrobla,项目名称:pyjuegos,代码行数:37,代码来源:runner.py

示例2: __call__

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __name__ [as 别名]
    def __call__(self, cls):
        """
        Decorate `cls`
        """
        expose_internal = self.expose_internal

        if self.submodule:
            self.name += "." + cls.__name__

        if self.name not in sys.modules:
            orig = ModuleType(self.name)
            orig.__name__ = self.name
            orig.__file__ = getfile(cls)
        else:
            orig = sys.modules[self.name]

        if isinstance(orig, ModuleFacade):
            raise TypeError("Facade() used inside module which is already "
                              "wrapped - only once Facade() allowed per module."
                              " inside {0}".format(orig))

        class _wrapper_cls(cls, ModuleFacade, ModuleType, object):
            _facade_wrapped = orig
            _facade_cls = cls

            def __dir__(self):
                items = set()
                items.update(self.__dict__)
                items.update(self._facade_cls.__dict__)

                if hasattr(self._facade_cls, "__dir__"):
                    items.update(self._facade_cls.__dir__(self))

                if expose_internal:
                    items.update(orig.__dict__)

                return sorted(items)

            def __getattr__(self, key):
                if expose_internal and hasattr(orig, key):
                    return getattr(orig, key)
                sup = super(_wrapper_cls, self)
                if hasattr(sup, "__getattr__"):
                    result = sup.__getattr__(key)
                    if result is not None:
                        return result
                raise AttributeError("'{0}' object has no attribute '{1}'"
                    .format(self, key))

        _wrapper_cls.__name__ = "ModuleFacade({0})".format(cls.__name__)
        inst = _wrapper_cls(self.name)
        sys.modules[self.name] = inst

        for key in "__name__ __doc__ __file__ __path__".split():
            if hasattr(orig, key):
                setattr(inst, key, getattr(orig, key))

        return inst
开发者ID:S-Bahrasemani,项目名称:rootpy,代码行数:60,代码来源:module_facade.py

示例3: make_module

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __name__ [as 别名]
def make_module(name, package="", **namespace):
    mod = ModuleType(name)
    mod.__package__ = package or ""
    if package:
        mod.__name__ = "{}.{}".format(package, name)
    else:
        mod.__name = name
    mod.__dict__.update(namespace)
    return mod
开发者ID:ales-erjavec,项目名称:orange-canvas,代码行数:11,代码来源:__init__.py

示例4: imports

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __name__ [as 别名]
    imp.acquire_lock()
    try:
      # The module *must* be in sys.modules before executing the code in case
      # the module code imports (directly or indirectly) itself (see PEP 302)
      sys.modules[module_fullname] = module
      if module_fullname_alias:
        sys.modules[module_fullname_alias] = module

      # This must be set for imports at least (see PEP 302)
      module.__file__ = '<' + relative_url + '>'

      # Only useful for get_source(), do it before exec'ing the source code
      # so that the source code is properly display in case of error
      module.__loader__ = self
      module.__path__ = []
      module.__name__ = module_fullname
      self.__fullname_source_code_dict[module_fullname] = source_code_str

      try:
        # XXX: Any loading from ZODB while exec'ing the source code will result
        # in a deadlock
        source_code_obj = compile(source_code_str, module.__file__, 'exec')
        exec source_code_obj in module.__dict__
      except Exception, error:
        del sys.modules[module_fullname]
        if module_fullname_alias:
          del sys.modules[module_fullname_alias]

        raise ImportError(
          "%s: cannot load Component %s (%s)" % (fullname, name, error)), \
          None, sys.exc_info()[2]
开发者ID:ccwalkerjm,项目名称:erp5,代码行数:33,代码来源:component_package.py


注:本文中的types.ModuleType.__name__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。