Skip to content

Instantly share code, notes, and snippets.

@sysr-q
Created November 11, 2013 07:59
Show Gist options
  • Save sysr-q/7409483 to your computer and use it in GitHub Desktop.
Save sysr-q/7409483 to your computer and use it in GitHub Desktop.
import inspect
__name__ = inspect.__name__
globals()["stack"] = inspect.stack()[0][0].f_globals[(__file__ + __name__)[len(__file__):]].stack()[0]
__file__, __name__ = [], "__builtins__"
for val, key in (("chr", "int"), ("any", "sum"), ("int", "chr")):
print(val, key, "??", [])
stack[0].f_locals["()"] = inspect.stack()[0][0].f_globals["__builtins__"].__dict__[val]
oops = vars()[repr(tuple())]
vars(stack.__getitem__(len(__file__)).f_globals[str(repr(__name__))[1:-1]])["list"] = vars(__builtins__)[key]
setattr(stack[0].f_globals[str(__name__)], key, oops)
globals()[val] = list
"""
All of the above achieves the same as:
chr, any, int = int, sum, chr
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment