Is their a command to view code?

Ian Kelly ian.g.kelly at gmail.com
Fri Mar 7 19:37:10 CET 2014


On Fri, Mar 7, 2014 at 10:55 AM, NexusRAwesome1995 .
<nexusrawesome at gmail.com> wrote:
> I am making a text based aventure game for my assignment and a friends test
> run has somehow saved over the entire code file and now im using an earlier
> version of the code. I have 0 idea if there is anyway to look at the code
> using the IDLE and i need to do it to see how i fixed the fatal error left
> behind by a friend. My on computer backup has not worked and the backup on
> my memory stick also has the same problem.
> If anyone knows of a way to get my code back i will be grateful as this is
> my 1st project and i'm not that used to the syntax.
> the item added is the outcome of what happened.

Sorry, Python doesn't keep the source code in memory.  If the game is
still running in the interpreter, you can ask it for the source code
of a particular code object, but it implements this by opening the
source file and reading it in.  Since you've overwritten the file, the
source code would be wrong.  The best that you could do in this case
would be to disassemble the code objects using the dis.dis() function,
and then try to reverse-engineer the Python code from the byte code.
If the interpreter is no longer running, then there is nothing you can
do.

For the future, I strongly recommend using a version control system,
such as the free and relatively lightweight Mercurial.  Then when you
have these kinds of mishaps all you have to do is check the most
recent version of the code out of the repository again.  You should of
course continue to create backups as well, in case of more disastrous
events (although memory sticks are far too failure-prone to be
considered a reliable backup solution IMO).



More information about the Python-list mailing list