'How to get python bytecode?
I've tried using py_compile to get me some bytecode examples (for learning needs).
However, this is what I get
file.py:
print("hello world")
file.pyc:
U
��Ob � @ s e d � dS )zhello worldN)�print� r r �test.py�<module> �
I guess I'm doing something terribly wrong, but I have no clue.
My base script is
import py_compile
py_compile.compile('test.py')
Solution 1:[1]
Are you looking for (the) dis module (documentation)?
Example:
>>> import dis
>>> def foo(a):
... return a * a
...
>>> dis.dis(foo)
2 0 LOAD_FAST 0 (a)
2 LOAD_FAST 0 (a)
4 BINARY_MULTIPLY
6 RETURN_VALUE
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
