Printing to the same line again and again?

Hey guys!

I’m wondering if there’s a way to delete text from the command line console that was printed earlier, so that I can print to the same line again and again.
I know that it’s possible with other scripting/programming languages - some people create animated ASCII art like that: http://www.asciimation.co.nz/

I would like to display some script output without spamming dozens of lines.

Cheers!
-Sascha

How about the ‘cls’ dos command?

I think what you are looking for is carriage return if you are interested in getting back to the beginning of the line without starting a new line. Although if your console does not support it you might not be able to use it in Python.

Here is a list of ascii escape codes that might help you out in Python

http://pythonweb.org/projects/webmodules/doc/0.5.3/html_multipage/lib/node48.html

Here is a simple code that demonstrates the concept

import time 

for a in range(1000):
    time.sleep(0.4)
    print " "+"\r%s"%a,

i think he’s going more for using a shell to show dynamic text on the same line, instead of printing out a huge log. sphinx, the python documentation generator, has code to do this. i haven’t looked into it myself, but they have a special logger that will show colored progress bars and generation status all through ascii text in a shell. it works on linux and osx, but probably not too well on windows, given it’s lackluster terminal support

hope that helps.

-chad

Ideally what you want an interface like Ncurses, but it is only available for Posix systems. This is an advanced terminal library. I have not written anything using it but I use alot of apps that use Ncurses.

Alternatively you can get Ncurses running under Windows via Cygwin environment.