Skip to content

Instantly share code, notes, and snippets.

@cleac
Created May 1, 2018 08:38
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 cleac/f4db16d2ff97d8eb45ceffc09ff9df61 to your computer and use it in GitHub Desktop.
Save cleac/f4db16d2ff97d8eb45ceffc09ff9df61 to your computer and use it in GitHub Desktop.
"import dis" article gist 3
>>> def string_generation_function(argument):
... return 'hello, {}'.format(argument)
...
>>> def function_for_dis():
... return [[string_generation_function('world')] for _ in range(10)]
...
>>> dis.dis(function_for_dis)
2 0 BUILD_LIST 0
3 LOAD_GLOBAL 0 (range)
6 LOAD_CONST 1 (10)
9 CALL_FUNCTION 1
12 GET_ITER
>> 13 FOR_ITER 21 (to 37)
16 STORE_FAST 0 (_)
19 LOAD_GLOBAL 1 (string_generation_function)
22 LOAD_CONST 2 ('world')
25 CALL_FUNCTION 1
28 BUILD_LIST 1
31 LIST_APPEND 2
34 JUMP_ABSOLUTE 13
>> 37 RETURN_VALUE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment