Method for clearing Python Window in ArcMap programmatically

2986
11
10-19-2018 06:26 AM
DarrenSmith
New Contributor III

Is there a way of clearing (flushing) the Python Window in ArcMap from Python (that works in 10.2.1)?

0 Kudos
11 Replies
DanPatterson_Retired
MVP Esteemed Contributor

like printing a bunch of blank lines? which just pushes what you see up off screen. otherwise no, that is an IDE thing

0 Kudos
DarrenSmith
New Contributor III

Thanks Dan, no it was aimed at getting back the memory it consumes, since it seems like it never gets truncated. I output messages to the Python Window for a couple of python addin tools (that are used a lot). The best solution is to stop doing that of course, but just wondered if there's an easy way to clear it.

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

del   but garbage collection (gc module) is worth a look.  When the tool is completed and closed it should free up stuff, at least on the python side

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

The short answer, no, or at least nothing that won't involve using a COM client to access ArcObjects.  If you are up for that, I would start in the Display (ArcObjects .NET 10.6 SDK) and Framework Library Contents (ArcObjects .NET 10.6 SDK) and look at the GPCommandWindow CoClass.

0 Kudos
DarrenSmith
New Contributor III

Thanks Joshua, it sounds like it'd be easier to stop abusing the use of the Python Window. I guess that I could probably get at the GPCommandWindow from Python via the comtypes library (http://sourceforge.net/projects/comtypes/).

0 Kudos
TedKowal
Regular Contributor II

I am a VB man and VB has a clear screen for its shell.....

I have not tried but ran across this:

https://www.geeksforgeeks.org/clear-screen-python/ 

:::: update did not work in the built in Python interpreter in ArcMap. However it did work external python console/ide

Right now I used for the built in Python interpreter: 

print "\n" * 80

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

Solved for a manual clean up... but no code interface

Since it isn't really a full-fledged python IDE.

From within a python ide, like Spyder or Jupyter QtConsole   … cls …  clears the screen...

You can save the Transcript if you want to move it to Spyder or one of the Jupter interfaces for further work.

DarrenSmith
New Contributor III

Thanks for taking the time to answer Ted and Dan. I'm really specifically after a way to clear(/reinitialize) the Python Window built-in to ArcMap via Python. It seems like the only way to achieve what I'm after (so far) is via ArcObjects.

0 Kudos
LukeWebb
Occasional Contributor III

The issue is if I write in the python window:      

data = []

for row in some_fc:

     data.append(row stuff)

I now have this in memory,. Clearing the screen is good, but I can still do :

print data

to get back my stuff, so memory is used. How to release this?

0 Kudos