爱的魔力转圈圈:仿shell风火轮进度条实现 Posted on 2020-08-22 Edited on 2023-07-04 In 指尖飞舞 今天在shell上安装Anaconda的时候,发现安装过程中的「风火轮」进度条很有趣,于是就简单实现了一下: 123456import timeicon = ['\\', '-', '/']for m in range(40): print('\rAll work and no play make Jack a dull boy: {}'.format(icon[m % 3]), end='') time.sleep(0.25) # -- control the r.p.m 无非就是把print函数的end='\n'换成end=''以便每次打印光标可以回到行首。再就是循环icon列表,制造「动画效果」。比如你要倒计时10s,每0.25s输出一帧,那么就要输出40帧。每一帧依次选取列表的下标可以用m对列表长度取余。 Post author: zxy Post link: https://ntifs.com/2020/08/22/爱的魔力转圈圈:仿shell风火轮进度条实现/ Copyright Notice: All articles in this blog are licensed under BY-NC-SA unless stating additionally.