[Tutor] Console output

Alan Gauld alan.gauld at freenet.co.uk
Wed Oct 5 22:09:27 CEST 2005


> 14% [=======> ] 344,192 16.28K/s ETA 02:19
>
> All the figures and the progress bar get continously updated. The only way 
> I
> know of sending output to the console is to use print or 
> sys.stdout.write(),
> but that would give me:
> 14% [=======> ] 344,192 16.28K/s ETA 02:19
> 18% [=========> ] 344,192 16.28K/s ETA 02:19
> 20% [============> ] 344,192 16.28K/s ETA 02:19

Usually thats done using curses which allows ypu to address the cursor on
the screen using coordinates. However for a single line you can fake it
using control codes for the specific terminal.

For example (as any vi user knows!) Ctrl J is line feed, Ctrl H is backspace
Ctrl G is beep(I think?), Ctrl U is delete to start of line, etc

You can use Ctrl H as a way of backspacing on the same line to the point
you want then inserying the updated text, or just use Ctrl U to delete the 
line
and rewrite it. You need to write to sys.stdout to do this properly and of
course don't ever write a newline until you are done!

HTH,

Alan G. 



More information about the Tutor mailing list