[Tutor] Re: clear screen [Let's make a feature request in Sourceforge!]

Magnus Lycka magnus@thinkware.se
Wed Nov 13 09:20:02 2002


At 23:19 2002-11-12 -0800, Danny Yoo wrote:
>If someone says that a part of the language doesn't feel clean and
>consistant, I think it's worth taking a look into it.  The clear screen
>issue has come up several times already on Tutor, so, clearly, there must
>be something that's very appealing about erasing the screen.  Chalkboards
>can be erased, and I get the feeling that people who are new to
>programming instinctively want that same refreshing feeling of "starting
>over"  that clearing the screen provides.

But the other basic means of output, print, stdout, stderr
are used in a lot of contexts where you can't assume a lot
about the reciever of the data. Data might go to a screen,
a printer, a file or into another program. Also raw_input
and input can read from pipes as well as from the keyboard.

For a screen, "clear" will certainly make sense. Perhaps
it could for communication with another programs as well,
but with the way normal OS pipes work, there is no generic
way of clearing already sent data. Should a clear send to
a file empty this file? Should it do nothing?

So for me, os.clear_screen() feels more like a short-cut
or a hack than like a natural part of a coherent whole.
Do you understand what I mean?

When we think about a clear_screen function, we are probably
implementing some kind of not entirely trivial user interface.
I think this might be a first stumbling block that will be
followed by others, like how do I move around a cursor on the
screen, create fields and menues etc. I fear that people who
ask for clear screen are likely to be on the path of reinventing
the square wheel...

UI building is something for tools like curses, Tkinter and
wxPython etc. If you try to build a non-trivial user interface
on print and raw_input, you have taken a wrong path.

The problem is that these tools are really too difficult for
new users. Maybe we need something like Visual Basic for Python.
Typically new users want, and expect, to write programs that can
interact with a user in a smooth way. Using pipes and data files
etc aren't what todays newbie typically has in mind...

Of course, fixing that is slightly more work than to fix a
clear screen function... :)

Guido once had the ambition to implement a standard way of
building user interfaces in Python, stdwin, but he gave up on
that years ago.

>Perhaps it might be worthwhile to ask the Python developers to add a
>function in the 'os' module to provide some kind of platform-independent
>console screen clearing code.

I fear that it would be to limited to make people happy.

>I can't confirm that it works on Win32 yet; can someone check this?

It works from the "DOS prompt" and it works from inside the standard
python interpreter. I changed the test code to print some stuff before
and after clearing with some delays, and it works as expected.

It doesn't work in IDLE or in PythonWin though. In both cases, a
Command window just flashes past. I have a feeling this might cause
more frustration that relief. (Both for newbies and for the rest of
us on the list.) I think we would need to have hooks for clearing the
screen in the GUI interpreter windows and that this generic function
would trigger that hook. I don't have a clue on how to do this though.

Or am I wrong? Is it enough that it works in simple text mode
programs, but not in IDLE, PythonWin etc? From the mails we got
recently, I got a feeling that people tried to do this in the IDEs.

>Once
>it checks out ok, we can submit this to Python's sourceforge as a feature
>request.  Who knows?  It might get in...

At least we will get a ruling, one way or another...



-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se