Possible Duplicate:
Replace console output in python
I am trying to write a program that outputs information including updates to the command line. What I mean by updates is, for example, if files are being processed by the program, perhaps it will keep an updated count of the files processed so far. So 1 file
is replaced with 2 files
and then with 3 files
and so forth.
The following is a sample piece of code that counts out some files and then displays a loading bar:
#!/bin/bash
for a in {1..10}
do
echo -ne " $a files processed.\r"
sleep 1
done
echo ""
echo -ne '##### (33%)\r'
sleep 1
echo -ne '############# (66%)\r'
sleep 1
echo -ne '####################### (100%)\r'
echo -ne '\n'
Basically, the command line output gets periodically overwritten giving the effect of a primitive text-based animation in the terminal.
There are two problems here:
- From what I know from doctors, the
echo
command is not portable at all. - I want to do this in a python program, not with a bash file.
Is there a way to achieve functionality similar to this using python?