fork(2) download
  1. import types
  2.  
  3. def inv(fn):
  4. t=fn.__code__
  5. c=list(t.co_code)
  6. idxs=[i+1 for i,j in enumerate(c) if j=='d' and c[i+1]!='\0']
  7. for i in range(len(idxs)/2):
  8. c[idxs[i]], c[idxs[-i-1]] = c[idxs[-i-1]], c[idxs[i]]
  9. outcode=types.CodeType( t.co_argcount, t.co_nlocals, t.co_stacksize, t.co_flags, ''.join(c), t.co_consts, t.co_names, t.co_varnames, t.co_filename, t.co_name, t.co_firstlineno, t.co_lnotab)
  10. return types.FunctionType(outcode, globals(), fn.__name__[::-1])
  11.  
  12. @inv
  13. def f():
  14. print 'Line1'
  15. print 'Line2'
  16. print 'Line3'
  17. print 'Line4'
  18.  
  19. f()
  20.  
Success #stdin #stdout 0.01s 7852KB
stdin
Standard input is empty
stdout
Line4
Line3
Line2
Line1