Activation of curses saves the current contents of the screen text screen of the terminal and clears the specified screen; exiting curses restores the contents of the screen (discards everything that was placed on the screen during the reign of the curses themselves). Try this version of your code and you will see what happens:
import curses, sys, time def test_streams(wot): print wot, "stdout" print >>sys.stderr, wot, "stderr" def curses_mode(stdscr): test_streams("wrap") time.sleep(1.0) test_streams("before") curses.wrapper(curses_mode) test_streams("after")
You will notice a wrap stderr on the screen for a second (during sleep) - it overwrites the stdout part - then it disappears and you see the four lines before and after the screen is now inactive (you can add other sleep to keep track of what is happening in more detail, if you're interested).
Alex martelli
source share