.pyc > .py ?

Brian McErlean b_mcerlean at yahoo.com
Sat Aug 3 18:43:08 EDT 2002


Matthias Huening <mhuening at zedat.fu-berlin.de> wrote in message news:<Xns925F5CCBF3021mhueningzedatfuberli at 130.133.1.4>...
> Hhmm, I'm afraid my editor ate up one of my modules... I don't 
> know how, but the file is gone...
> I still have a compiled .pyc-version. So here is my question: 
> is it possible to get back the source file from the .pyc file?
> How?
> 
> Thanks, Matthias

Take a look at decompyle (http://www.goebel-consult.de/decompyle/)

To restore a missing myfile.py from the myfile.pyc bytecode you can
do:

>>>import decompyle
>>>outputfile = open('myfile.py','w')
>>>decompyle.decompyle_file('myfile.pyc',outputfile)

This should restore the code nearly identical to the source, though
you will lose any comments and the exact layout of your code, since
these won't be preserved in the .pyc file.

Brian.



More information about the Python-list mailing list