__init__.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:femtocode 作者: diana-hep 项目源码 文件源码
def compile_func(ast_node, filename, globals, **defaults):
    '''
    Compile a function from an ast.FunctionDef instance.

    :param ast_node: ast.FunctionDef instance
    :param filename: path where function source can be found. 
    :param globals: will be used as func_globals

    :return: A python function object
    '''

    funcion_name = ast_node.name
    module = _ast.Module(body=[ast_node])

    ctx = {'%s_default' % key : arg for key, arg in defaults.items()}

    code = compile(module, filename, 'exec')

    eval(code, globals, ctx)

    function = ctx[funcion_name]

    return function

#from imp import get_magic
#
#def extract(binary):
#    
#    if len(binary) <= 8:
#        raise Exception("Binary pyc must be greater than 8 bytes (got %i)" % len(binary))
#    
#    magic = binary[:4]
#    MAGIC = get_magic()
#    
#    if magic != MAGIC:
#        raise Exception("Python version mismatch (%r != %r) Is this a pyc file?" % (magic, MAGIC))
#    
#    modtime = time.asctime(time.localtime(struct.unpack('i', binary[4:8])[0]))
#
#    code = marshal.loads(binary[8:])
#    
#    return modtime, code
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号