本文整理汇总了Python中types.FunctionType.__module__方法的典型用法代码示例。如果您正苦于以下问题:Python FunctionType.__module__方法的具体用法?Python FunctionType.__module__怎么用?Python FunctionType.__module__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类types.FunctionType
的用法示例。
在下文中一共展示了FunctionType.__module__方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _deserialize_func
# 需要导入模块: from types import FunctionType [as 别名]
# 或者: from types.FunctionType import __module__ [as 别名]
def _deserialize_func(funcs, globalDict):
items = pickle.loads(funcs)
res = None
for objType, name, data in items:
if objType == 'func':
codeArgs, funcArgs, updatedGlobals = pickle.loads(data)
code = CodeType(*codeArgs)
globalDict.update(**updatedGlobals)
value = FunctionType(code, globalDict, *funcArgs)
elif objType == 'mod':
value = __import__(data)
elif objType == 'oldclass':
class_name, module, bases, class_dict = data
value = typesmod.ClassType(class_name, bases, {k:_deserialize_func(v, globalDict) for k, v in class_dict.items()})
value.__module__ = module
elif objType == 'type':
raise Exception('deserialize type')
else:
raise Exception('Unknown serialization type')
globalDict[name] = value
if res is None:
res = value
return res
示例2: _create_function
# 需要导入模块: from types import FunctionType [as 别名]
# 或者: from types.FunctionType import __module__ [as 别名]
def _create_function(fcode, fglobals, fname=None, fdefaults=None, fclosure=None, fdict=None, mod_name=None):
# same as FunctionType, but enable passing __dict__ to new function,
# __dict__ is the storehouse for attributes added after function creation
log.info('loading function: ' + fname)
fdict = fdict or dict()
fglobals = fglobals or {}
func = FunctionType(fcode, fglobals, fname, fdefaults, fclosure)
func.__dict__.update(fdict)
func.__module__ = mod_name
return func
示例3: interactive
# 需要导入模块: from types import FunctionType [as 别名]
# 或者: from types.FunctionType import __module__ [as 别名]
def interactive(f):
"""decorator for making functions appear as interactively defined.
This results in the function being linked to the user_ns as globals()
instead of the module globals().
"""
# build new FunctionType, so it can have the right globals
# interactive functions never have closures, that's kind of the point
if isinstance(f, FunctionType):
mainmod = __import__("__main__")
f = FunctionType(f.__code__, mainmod.__dict__, f.__name__, f.__defaults__)
# associate with __main__ for uncanning
f.__module__ = "__main__"
return f