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


Python FunctionType.__module__方法代码示例

本文整理汇总了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
开发者ID:amykatenicho,项目名称:Azure-MachineLearning-ClientLibrary-Python,代码行数:29,代码来源:services.py

示例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
开发者ID:wxiang7,项目名称:dill,代码行数:12,代码来源:dill.py

示例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
开发者ID:JuDa-hku,项目名称:ipython,代码行数:16,代码来源:util.py


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