From: vsoler on
Hi everyone,

When I run a python script, I know that I can print the results of my
calculations on the Interactive Window. Once the scripts ends, I can
copy/pate these results on an OpenOffice Writer document.

However, I would like to know if I can somehow add some lines to my
script, so that it saves the Interactive Window to a text file. How
could it be done?

And, is there a way to programatically clear out the Interactive
Window so that it only shows the last run?

Thank you for your help
From: Mark Hammond on
On 22/02/2010 4:28 AM, vsoler wrote:
> Hi everyone,
>
> When I run a python script, I know that I can print the results of my
> calculations on the Interactive Window. Once the scripts ends, I can
> copy/pate these results on an OpenOffice Writer document.
>
> However, I would like to know if I can somehow add some lines to my
> script, so that it saves the Interactive Window to a text file. How
> could it be done?

The code for the interactive window is in pywin32\framework\interact.py
- eg:

>>> from pywin.framework import interact
>>> interact.IsInteractiveWindowVisible()
True
>>>

If it is visible, then something like:

>>> len(interact.edit.currentView.GetWindowText())
189
>>>

should get you on the right path.

>
> And, is there a way to programatically clear out the Interactive
> Window so that it only shows the last run?

Something like:

interact.edit.currentView.GetWindowText('line1\nline2\nline3')

should work - the first few lines will always be formatted using blue
text, and the above works a little strangely when attempting it directly
from the interactive prompt, but might still be useful. See the source
file I mentioned above for more clues.

HTH,

Mark
>
> Thank you for your help