jweinst1
5/7/2016 - 5:56 AM

dis bytecode for python learning example

dis bytecode for python learning example

import dis

def foo(x):
	for elem in range(x):
		print(elem)
		

print(dis.dis(foo))

"""  4           0 SETUP_LOOP              30 (to 33)
              3 LOAD_GLOBAL              0 (range)
              6 LOAD_FAST                0 (x)
              9 CALL_FUNCTION            1 (1 positional, 0 keyword pair)
             12 GET_ITER
        >>   13 FOR_ITER                16 (to 32)
             16 STORE_FAST               1 (elem)

  5          19 LOAD_GLOBAL              1 (print)
             22 LOAD_FAST                1 (elem)
             25 CALL_FUNCTION            1 (1 positional, 0 keyword pair)
             28 POP_TOP
             29 JUMP_ABSOLUTE           13
        >>   32 POP_BLOCK
        >>   33 LOAD_CONST               0 (None)
             36 RETURN_VALUE
None"""