本文整理汇总了Python中types.FunctionType.func_dict方法的典型用法代码示例。如果您正苦于以下问题:Python FunctionType.func_dict方法的具体用法?Python FunctionType.func_dict怎么用?Python FunctionType.func_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类types.FunctionType
的用法示例。
在下文中一共展示了FunctionType.func_dict方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: buildFunction
# 需要导入模块: from types import FunctionType [as 别名]
# 或者: from types.FunctionType import func_dict [as 别名]
def buildFunction(baseFunc, code=None, glbls=None,
name=None, defaults=None,
kwdefaults=None, closure=None,
annotations=None, doc=None, dct=None):
resf = None
def _f():
pass
if hasattr(_f, 'func_code'):
# Python 2.x
resf = FunctionType(code or baseFunc.func_code,
glbls or baseFunc.func_globals,
name or baseFunc.func_name,
defaults or baseFunc.func_defaults,
closure or baseFunc.func_closure)
resf.func_dict = dct or baseFunc.func_dict
resf.func_doc = doc or baseFunc.func_doc
else:
# Python 3.x
resf = FunctionType(code or baseFunc.__code__,
glbls or baseFunc.__globals__,
name or baseFunc.__name__,
defaults or baseFunc.__defaults__,
closure or baseFunc.__closure__)
resf.__kwdefaults__ = kwdefaults or baseFunc.__kwdefaults__
resf.__annotations__ = annotations or baseFunc.__annotations__
resf.__dict__ = dct or baseFunc.__dict__
resf.__doc__ = doc or baseFunc.__doc__
return resf
示例2: loads_function
# 需要导入模块: from types import FunctionType [as 别名]
# 或者: from types.FunctionType import func_dict [as 别名]
def loads_function(s):
'''Restores a function serialized with :func:`dumps_function`.'''
name, code, globals_, defaults, closure, func_dict = loads(s)
code = marshal.loads(code)
for k, v in globals_.iteritems():
if isinstance(v, Module):
globals_[k] = v.mod
if closure is not None:
import ctypes
ctypes.pythonapi.PyCell_New.restype = ctypes.py_object
ctypes.pythonapi.PyCell_New.argtypes = [ctypes.py_object]
closure = tuple(ctypes.pythonapi.PyCell_New(c) for c in closure)
r = FunctionType(code, globals_, name, defaults, closure)
r.func_dict = func_dict
return r