Skip to content

Instantly share code, notes, and snippets.

@hellerbarde
Created Oct 6, 2014
Embed
What would you like to do?
Demo of the dis module
In [1]: import dis
In [2]: def foo(what):
...: a = []
...: a = a+4
...: print a[0]
...: b = what[1:4]
...: print b[-1]
...:
In [3]: dis.dis(foo)
2 0 BUILD_LIST 0
3 STORE_FAST 1 (a)
3 6 LOAD_FAST 1 (a)
9 LOAD_CONST 1 (4)
12 BINARY_ADD
13 STORE_FAST 1 (a)
4 16 LOAD_FAST 1 (a)
19 LOAD_CONST 2 (0)
22 BINARY_SUBSCR
23 PRINT_ITEM
24 PRINT_NEWLINE
5 25 LOAD_FAST 0 (what)
28 LOAD_CONST 3 (1)
31 LOAD_CONST 1 (4)
34 SLICE+3
35 STORE_FAST 2 (b)
6 38 LOAD_FAST 2 (b)
41 LOAD_CONST 4 (-1)
44 BINARY_SUBSCR
45 PRINT_ITEM
46 PRINT_NEWLINE
47 LOAD_CONST 0 (None)
50 RETURN_VALUE
In [4]:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment