Retrieve Python window code from previous session

4547
7
05-31-2016 11:12 AM
DarrenWiens2
MVP Honored Contributor

Is there any way to retrieve Python code entered and executed in the Python window from a previous session, similar to Results? The situation is that I was debugging what evolved into a somewhat convoluted section of code, and then crashed ArcMap.

0 Kudos
7 Replies
RebeccaStrauch__GISP
MVP Esteemed Contributor

In the Python window, right-click and "Save as".  This will save all the typed commands...working or not, without all the returned messages.  You can then clean up the file, and actually "Load" it to have it execute in the window again.

Also, I have the "Add to Results" checked, so anything that runs here is also added to the results.

But, if it crashes before you get to save, or close out successfully (for the results)...I'm not sure, and would also be curious.  Maybe you can have a script that always does an auto "Save as"???

DarrenWiens2
MVP Honored Contributor

Thanks, Rebecca. I wasn't aware that there was a right-click context menu for the Python window.

My current "safety" method is to select my script and copy/paste to an external text editor in case of crash. I don't necessarily want to save script files for all my scratch scripts, and using "Save As..." I would still have to remember to do it before a crash. "Add to Results" only adds geoprocessing tool runs, and my scripts are generally more cursor-based, so that doesn't quite do what I need.

In any case, I suppose the answer is to do the bulk of my work in a proper IDE that doesn't crash nearly as often as ArcMap, and also enables my compulsive "Ctrl+S" saving habit.

edit: I'm still holding out hope that someone knows of a secret log file that records Python window activity.

0 Kudos
RebeccaStrauch__GISP
MVP Esteemed Contributor

I can relate.....really bums me out after long stretch of testing to have it crash and lose everything.  I do the same as you many times...mass copy-paste.  Nice thing about the SaveAs however, you don't have to clean up all the >> and returned messages....just what you typed.  So worth it when you remember.  Many times my script rely on the open MXD so can't always strictly use the IDE (I use Wing Pro myself)

But good to know it already exists in ArcGIS Pro....if it does actually keep it as you go, and doesn't rely on a clean exit (i.e. if it saves even with a crash....)

0 Kudos
DavidWynne
Esri Contributor

Hi Darren,

In ArcGIS Pro there is. If you look under the folder C:\Users\<user_name>\AppData\Local\ESRI\Local Caches, there is a file name py_repl.history that includes code run from the Python window.

-Dave

DarrenWiens2
MVP Honored Contributor

Ahh, thanks, David. It doesn't look like this exists at 10.2.2.

0 Kudos
DavidWynne
Esri Contributor

Right, it's only in ArcGIS Pro. In ArcMap, you'd have to save as you go as Rebecca Strauch​ suggested, as the code isn't retained.

0 Kudos
RebeccaStrauch__GISP
MVP Esteemed Contributor

Check out https://community.esri.com/ideas/1447   

As mention, the old "&watch"  or maybe "&echo on".

0 Kudos