本文整理汇总了Python中types.ModuleType.__package__方法的典型用法代码示例。如果您正苦于以下问题:Python ModuleType.__package__方法的具体用法?Python ModuleType.__package__怎么用?Python ModuleType.__package__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类types.ModuleType
的用法示例。
在下文中一共展示了ModuleType.__package__方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_module
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __package__ [as 别名]
def load_module(self, fullname):
print "load", fullname
if fullname.endswith("test"):
return 1
else:
r = ModuleType(fullname)
r.__package__ = fullname
r.__path__ = []
return r
示例2: make_module
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __package__ [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
示例3: new_module
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __package__ [as 别名]
def new_module(self, module_name, file_path):
self.module_name = module_name
module = ModuleType(module_name)
module.__package__ = module_name.rpartition('.')[0]
module.__file__ = file_path
module.__loader__ = FileWithMacrosLoader(module_name, module)
return module
示例4: import_file
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __package__ [as 别名]
def import_file(filename, name = None, package = None, add_to_sys_modules = False):
if os.path.isdir(filename):
filename = os.path.join(filename, "__init__.py")
if name is None:
name = os.path.basename(filename).split(".")[0]
dirname = os.path.basename(os.path.dirname(filename)).strip()
if name == "__init__" and dirname:
name = dirname
elif package is not None:
name = package + "." + name
mod = ModuleType(name)
mod.__file__ = os.path.abspath(filename)
if package is not None:
mod.__package__ = package
mod.__path__ = [os.path.dirname(mod.__file__)]
if add_to_sys_modules:
sys.modules[name] = mod
execfile(filename, mod.__dict__)
return mod
示例5: new_module
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __package__ [as 别名]
def new_module(name, package_name=None):
mod = ModuleType(name)
if package_name:
mod.__package__ = package_name
return mod