def compile_func(arg_names, statements, name='_the_func', debug=False):
 if six.PY2:
  func_def = ast.FunctionDef(name=name.encode('utf-8'), args=ast.arguments(args=[ast.Name(n, ast.Param()) for n in arg_names], vararg=None, kwarg=None, defaults=[ex_literal(None) for _ in arg_names]), body=statements, decorator_list=[])
 else:
  func_def = ast.FunctionDef(name=name, args=ast.arguments(args=[ast.arg(arg=n, annotation=None) for n in arg_names], kwonlyargs=[], kw_defaults=[], defaults=[ex_literal(None) for _ in arg_names]), body=statements, decorator_list=[])
 mod = ast.Module([func_def])
 ast.fix_missing_locations(mod)
 prog = compile(mod, '<generated>', 'exec')
 if debug:
  dis.dis(prog)
  for const in prog.co_consts:
   if isinstance(const, types.CodeType):
    dis.dis(const)
 the_locals = {}
 exec prog in {}, the_locals
 return the_locals[name]

def compile_func ( arg_names , statements , name = '_the_func' , debug = False ) : if six . PY2 : func_def = ast . FunctionDef ( name = name . encode ( 'utf-8' ) , args = ast . arguments ( args = [ ast . Name ( n , ast . Param ( ) ) for n in arg_names ] , vararg = None , kwarg = None , defaults = [ ex_literal ( None ) for _ in arg_names ] ) , body = statements , decorator_list = [ ] ) else : func_def = ast . FunctionDef ( name = name , args = ast . arguments ( args = [ ast . arg ( arg = n , annotation = None ) for n in arg_names ] , kwonlyargs = [ ] , kw_defaults = [ ] , defaults = [ ex_literal ( None ) for _ in arg_names ] ) , body = statements , decorator_list = [ ] ) mod = ast . Module ( [ func_def ] ) ast . fix_missing_locations ( mod ) prog = compile ( mod , '<generated>' , 'exec' ) if debug : dis . dis ( prog ) for const in prog . co_consts : if isinstance ( const , types . CodeType ) : dis . dis ( const ) the_locals = { } exec prog in { } , the_locals return the_locals [ name ]
compile a list of statements as the body of a function and return the resulting python function .