黑松山资源网 Design By www.paidiu.com
最近需要用Python写一个小脚本,用到了一些小知识,赶紧抽空记录一下。不深但是常用。
两个进度条示例,拷贝就能运行:
# coding=utf-8 import sys import time # width:宽度, percent:百分比 def progress(width, percent): print "\r%s %d%%" % (('%%-%ds' % width) % (width * percent / 100 * '='), percent), if percent >= 100: print sys.stdout.flush() # 示例一、0%--100% def demo1(): for i in xrange(100): progress(50, (i + 1)) time.sleep(0.1) ## 示例二、周期加载 def demo2(): i = 19 n = 200 while n > 0: print "\t\t\t%s \r" % (i * "="), i = (i + 1) % 20 time.sleep(0.1) n -= 1 demo1() demo2()
提供一个自己写的一个简单异步进度条,可以在耗时操作前开启,然后再耗时操作结束后停止。
import time import thread import sys class Progress: def __init__(self): self._flag = False def timer(self): i = 19 while self._flag: print "\t\t\t%s \r" % (i * "="), sys.stdout.flush() i = (i + 1) % 20 time.sleep(0.05) print "\t\t\t%s\n" % (19 * "="), thread.exit_thread() def start(self): self._flag = True thread.start_new_thread(self.timer, ()) def stop(self): self._flag = False time.sleep(1)
用法:
progress = Progress() progress.start() time.sleep(5) progress.stop()
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
更新日志
2024年10月09日
2024年10月09日
- 【原神】V5.0攻略 | 林尼攻略一图流
- 李翊君.1993-相思的烈酒【上华】【WAV+CUE】
- 古巨基.1998-LEO.KU(国)【千禧年代】【WAV+CUE】
- 郭子.2001-原来你什么都不想要创作集丫滚石】【WAV+CUE】
- 《使命召唤:黑色行动6》新预告公布!10月25日发售
- Atlus《暗喻幻想》媒体评分汇总:高分好评如潮!
- 2024金摇杆奖提名揭晓 《黑神话》角逐最佳视觉设计!
- 群星《新说唱2024 第3期 (上)》[320K/MP3][32.76MB]
- 群星《新说唱2024 第3期 (上)》[FLAC/分轨][95.38MB]
- 群星《新说唱2024 第3期 (下)》[320K/MP3][31.36MB]
- 幻兽帕鲁手游什么时候正式上线 最新消息一览
- 西普大陆BOSS位置盘点 解锁天启纪元玩法
- 西普大陆精灵进阶培养攻略 精灵养成指南
- dnf手游法控法系职业哪个强 dnf手游法控法系职业强度排行
- 魔兽世界血藤护目镜图纸在哪买 wlk血藤护目镜图纸购买位置介绍