Here's a progressbar class I wrote some time ago, hope it helps.
-Larry
class progressbarClas s:
def __init__(self, finalcount, progresschar=No ne):
import sys
self.finalcount =finalcount
self.blockcount =0
#
# See if caller passed me a character to use on the
# progress bar (like "*"). If not use the block
# character that makes it look like a real progress
# bar.
#
if not progresschar: self.block=chr( 178)
else: self.block=prog resschar
#
# Get pointer to sys.stdout so I can use the write/flush
# methods to display the progress bar.
#
self.f=sys.stdo ut
#
# If the final count is zero, don't start the progress gauge
#
if not self.finalcount : return
self.f.write('\ n------------------ %
Progress -------------------1\n')
self.f.write(' 1 2 3 4 5 6 7 8 9 0\n')
self.f.write('----0----0----0----0----0----0----0----0----0----0\n')
return
def progress(self, count):
#
# Make sure I don't try to go off the end (e.g. >100%)
#
count=min(count , self.finalcount )
#
# If finalcount is zero, I'm done
#
if self.finalcount :
percentcomplete =int(round(100* count/self.finalcount ))
if percentcomplete < 1: percentcomplete =1
else:
percentcomplete =100
#print "percentcomplet e=",percentcomp lete
blockcount=int( percentcomplete/2)
#print "blockcount=",b lockcount
if blockcount > self.blockcount :
for i in range(self.bloc kcount,blockcou nt):
self.f.write(se lf.block)
self.f.flush()
if percentcomplete == 100: self.f.write("\ n")
self.blockcount =blockcount
return
if __name__ == "__main__":
from time import sleep
pb=progressbarC lass(8,"*")
count=0
while count<9:
count+=1
pb.progress(cou nt)
sleep(0.2)
pb=progressbarC lass(100)
pb.progress(20)
sleep(0.2)
pb.progress(47)
sleep(0.2)
pb.progress(90)
sleep(0.2)
pb.progress(100 )
print "testing 1:"
pb=progressbarC lass(1)
pb.progress(1)
<fo***********@ anonym.hu> wrote in message
news:ma******** *************** **************@ python.org...
Hi !
I want to print, but without newline. I want to create a progress for
ftp, but the print is drop a newline for every percent.
I want like this:
0% 25% 50% 75% 100%
But this happening:
0%
25%
50%
75%
100%
How to I prevent the newlines ?
Thanx for help:
FT