fork(2) download
  1. # your code goes here
  2. import inspect
  3. def mess_with_caller(funcname):
  4. stack = inspect.stack()
  5. try:
  6. locals_ = stack[1][0].f_locals
  7. finally:
  8. del stack
  9. locals_[funcname] = lambda : 'yaaaaaay'
  10.  
  11.  
  12. mess_with_caller('global_new_function')
  13. print global_new_function()
  14.  
  15. def a_func():
  16. mess_with_caller('inner_new_function')
  17. try:
  18. print inner_new_function()
  19. except:
  20. print 'Oh. That didn\'t work.'
  21.  
  22. a_func()
  23.  
Success #stdin #stdout 0.07s 8824KB
stdin
Standard input is empty
stdout
yaaaaaay
Oh. That didn't work.