how to extract source code from code objects ?

Jp Calderone exarkun at intarweb.us
Thu Jan 2 11:35:45 EST 2003


On Thu, Jan 02, 2003 at 08:14:52AM -0800, Michele Simionato wrote:
> I can compile a string in a code object:
> 
> >>> code_object=compile('x=1','<string>','exec')
> 
> now the code_object.co_code attribute contains the bytecode corresponding
> to the statement x=1:
> 
> >>> code_object.co_code
> '\x7f\x00\x00\x7f\x01\x00d\x00\x00Z\x00\x00d\x01\x00S'
> 
> Is there a way to have back the source code, i.e. the string 'x=1'
> instead of the bytecode ?
> TIA,

>>> import decompyle
>>> decompyle.decompyle(compile('x=1', '<string>', 'exec'))
x = 1

  http://www.crazy-compilers.com/decompyle/

  Jp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20030102/5720a595/attachment.sig>


More information about the Python-list mailing list