Clearing the screen

Felipe Almeida Lessa felipe.lessa at gmail.com
Sat Feb 11 15:14:02 EST 2006


Em Sáb, 2006-02-11 às 12:04 -0800, mwt escreveu:
> I'm doing some python programming for a linux terminal (just learning).
> When I want to completely redraw the screen, I've been using
> os.system("clear")
> This command works when using python in terminal mode, and in IDLE.
> However, when running a little .py file containing that command, the
> screen doesn't clear. 
> 
> What to do?

There's one escape sequence that does what you want.

I am *not* sure if this solution is the correct one, but:

$ clear | hd
00000000  1b 5b 48 1b 5b 32 4a                              |.[H.[2J|
00000007
$ python
Python 2.3.5 (#2, Nov 20 2005, 16:40:39)
[GCC 4.0.3 20051111 (prerelease) (Debian 4.0.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print
chr(0x1b)+chr(0x5b)+chr(0x48)+chr(0x1b)+chr(0x5b)+chr(0x32)+chr(0x4a),
>>> # Clears the screen!

-- 
"Quem excele em empregar a força militar subjulga os exércitos dos
outros povos sem travar batalha, toma cidades fortificadas dos outros
povos sem as atacar e destrói os estados dos outros povos sem lutas
prolongadas. Deve lutar sob o Céu com o propósito primordial da
'preservação'. Desse modo suas armas não se embotarão, e os ganhos
poderão ser preservados. Essa é a estratégia para planejar ofensivas."

  -- Sun Tzu, em "A arte da guerra"




More information about the Python-list mailing list