- 论坛徽章:
- 0
|
我就是想在控制台下运行下载程序的时候进行如下的显示
- 下载线程1的文字提示-----10%
- 下载线程2的文字提示-----10%
- 下载线程3的文字提示-----10%
复制代码
但我努力了半天还是不行,如果是单线程的情况下我就是用 先显示 一个数字 然后在 \b\b\b\b 退回,然后在显示。但这样还有问题。Print 加逗号 显示有一个强制的空格。
经过反复试验后,我写出了一个类。适合单线程的程序。如果多线程的话,就成了。
- 下载进程1的文字提示-----下载进程2的文字提示-----下载进程3的文字提示-----10%
复制代码
不知道有没有解决的方法啊。快疯了。。我写这个类是给我的下载程序用的。
可以看
http://bbs.chinaunix.net/viewthread.php?tid=796303&extra=page%3D1
最后是我写的显示进度类代码
- # Class Name: Progress Number Class
- #
- # Author: rikioy
- #
- # Email: rikioy at gmail DOT com
- #
- # Date: 07/23/2006
- #
- #
- class progressNumber:
- "Print prgress number behind the string."
- def __init__( self,finalcount):
- self.finalcount = finalcount
- def progress(self,count):
- "Update the current progress."
-
- count = min(count,self.finalcount)
- if self.finalcount:
- percentcomplete = int(round(100*count/self.finalcount))
-
- if percentcomplete < 10:
- print "%d%%" % percentcomplete,
- print "\b\b\b\b",
- else:
- print "%d%%" % percentcomplete,
- print "\b\b\b\b\b",
- else:
- pass
- if __name__ == '__main__':
- from time import sleep
-
- print "Name : Class prgressNumber"
- print "Class __doc__ : %s\n" % progressNumber.__doc__
-
- print "Demo."
- #notice: Add one comma behind the string
- #When you use comma in print,the pring don't output '\n'
- print "Display the progress behind this string.",
- pn = progressNumber(70)
- count = 0
- while count < 70:
- count += 1
- pn.progress(count)
- sleep(0.1)
复制代码
[ 本帖最后由 rikioy 于 2006-7-24 19:04 编辑 ] |
|