Rebuild Python bytecode with source code?

This may be a stupid question, but given the result, let's say ...

>>> from dis import dis >>> def myfunc(x): ... print x ** 2 ... >>> dis(myfunc) 2 0 LOAD_FAST 0 (x) 3 LOAD_CONST 1 (2) 6 BINARY_POWER 7 PRINT_ITEM 8 PRINT_NEWLINE 9 LOAD_CONST 0 (None) 12 RETURN_VALUE 

.. or .pyc - is it possible to assemble it into a valid Python source code fragment? Ie where reassemble(dis(myfunc)) == "def reassembled_function(x):\n print x ** 2"

Not for any specific practical reason, I am just wondering if this is possible or has been undertaken.

Related

  • A free Python decompiler that is not an online service?
+7
python bytecode bytecode-manipulation
source share
1 answer
+5
source share

All Articles