import sys import types load_fast_program = bytes([ 124, 200, 200, # LOAD_FAST (200<<8)+200 83, # RETURN_VALUE ]) store_fast_program = bytes([ 100, 0, 0, # LOAD_CONST 0 125, 200, 200, # LOAD_FAST (200<<8)+200 83, # RETURN_VALUE ]) delete_fast_program = bytes([ 126, 200, 200, # DELETE_FAST (200<<8)+200 83, # RETURN_VALUE ]) # program = load_fast_program program = store_fast_program # program = delete_fast_program args = [ 0, # argcount 0, # kwonlyargcount -- python 3 only 0, # nlocals 1, # stacksize 67, # flags program, # codestring (None,), # constants (), # names (), # varnames '',# filename '', # name (of function) 1, # firstlineno b'', # lnotab (), # freevars (), # cellvars ] if sys.version_info.major == 2: del args[1] code_object = types.CodeType(*args) function = types.FunctionType(code_object, globals()) function()