Skip to content

Instantly share code, notes, and snippets.

@Zagrebelin
Created December 17, 2016 20:35
Show Gist options
  • Save Zagrebelin/df22ab5789f0be83c2d83308f1f5bafc to your computer and use it in GitHub Desktop.
Save Zagrebelin/df22ab5789f0be83c2d83308f1f5bafc to your computer and use it in GitHub Desktop.
import dis
dis.dis("""
try:
print(2)
except ValueError as e:
print(1)""")
2 0 SETUP_EXCEPT 14 (to 17)
3 3 LOAD_NAME 0 (print)
6 LOAD_CONST 0 (2)
9 CALL_FUNCTION 1 (1 positional, 0 keyword pair)
12 POP_TOP
13 POP_BLOCK
14 JUMP_FORWARD 47 (to 64)
4 >> 17 DUP_TOP
18 LOAD_NAME 1 (ValueError)
21 COMPARE_OP 10 (exception match)
24 POP_JUMP_IF_FALSE 63
27 POP_TOP
28 STORE_NAME 2 (e)
31 POP_TOP
32 SETUP_FINALLY 15 (to 50)
5 35 LOAD_NAME 0 (print)
38 LOAD_CONST 1 (1)
41 CALL_FUNCTION 1 (1 positional, 0 keyword pair)
44 POP_TOP
45 POP_BLOCK
46 POP_EXCEPT
47 LOAD_CONST 2 (None)
>> 50 LOAD_CONST 2 (None)
53 STORE_NAME 2 (e)
56 DELETE_NAME 2 (e)
59 END_FINALLY
60 JUMP_FORWARD 1 (to 64)
>> 63 END_FINALLY
>> 64 LOAD_CONST 2 (None)
67 RETURN_VALUE
[Finished in 0.4s]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment