Skip to content

Instantly share code, notes, and snippets.

@ashwin
Created May 1, 2013 04:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashwin/5493670 to your computer and use it in GitHub Desktop.
Save ashwin/5493670 to your computer and use it in GitHub Desktop.
Disassembling a Python method to its bytecode
$ cat foo.py
def bar():
a = 10
b = 2
c = a + b
$ python
>>> import dis
>>> import foo
>>> dis.dis(foo.bar)
2 0 LOAD_CONST 1 (10)
3 STORE_FAST 0 (a)
3 6 LOAD_CONST 2 (2)
9 STORE_FAST 1 (b)
4 12 LOAD_FAST 0 (a)
15 LOAD_FAST 1 (b)
18 BINARY_ADD
19 STORE_FAST 2 (c)
22 LOAD_CONST 0 (None)
25 RETURN_VALUE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment