.py from .pyc

Jan Olderdissen jolderdissen at ixiacom.com
Tue May 6 12:26:28 EDT 2003


Markus,

>I recently deleted a .py file and have the remaining .pyc.
>Can I reconstruct the .py file from the .pyc?
>How can I do it?

You're mostly out of luck. .pyc is compiled python byte-code.
Reconstructing your exact code from it is not possible.

There are tools for retrieving deleted files from various operating
systems. You might want to look into those first:
http://www.webopedia.com/DidYouKnow/Hardware_Software/2002/Erasing_Deleted_Files.asp

If you're really desperate, there is a disassembler for Python
byte-code: http://www.python.org/doc/current/lib/module-dis.html. It
will give you an approximate idea what the code was doing and also
enable you to retrieve symbols.

Going forward, I strongly suggest regular backups and using source
control software, for example CVS http://www.cvshome.org/ (free, both
as in beer and in speech).

Jan




More information about the Python-list mailing list