Created
October 6, 2014 14:21
-
-
Save hellerbarde/4c572a446244cd9ee37c to your computer and use it in GitHub Desktop.
Demo of the dis module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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