Guest User

Untitled

a guest
Jun 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.24 KB | None | 0 0
  1. import ast
  2. import codegen
  3.  
  4. expr="""
  5. def foo():
  6. print("hello world")
  7. """
  8. p=ast.parse(expr)
  9.  
  10. p.body[0].body = [ ast.parse("return 42").body[0] ] # Replace function body with "return 42"
  11.  
  12. print(codegen.to_source(p))
  13.  
  14. def foo():
  15. return 42
Add Comment
Please, Sign In to add comment