84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
我在尝试写个命令行的fm,但是碰到播放时间的适合遇到了问题,如何实现一个计时器,每次自减1秒后覆盖之前的print 输出我想把歌曲总时间传入如下代码,封装个函数,但是如何覆盖上一次print的结果呢?
def remain(min) count = 0 while (count < min): count += 1 n = min - count time.sleep(1) print n
学习是最好的投资!
先科普下,"\r" 表示光标回到行首(参考自ascii编码表)。利用它就能达到覆盖字符的效果,但前提是别换行(消灭\n)。来吧~ 看吾主的神迹。
pythonline = "=============================" print(line + "\r" + line, end='');print("\r" + line + "\r" + line)
python
line = "=============================" print(line + "\r" + line, end='');print("\r" + line + "\r" + line)
再补充个进度条demo
pythonimport time lineLength = 20 delaySeconds = 0.05 frontSymbol = '=' frontSymbol2 = ['—', '\\', '|', '/'] backSymbol = ' ' for i in range(10): lineTmpla = "{:%s<%s} {} {:<2}"%(backSymbol, lineLength) for j in range(lineLength): tmpSymbol = frontSymbol2[j%(len(frontSymbol2))] print("\r" + lineTmpla.format(frontSymbol * j, tmpSymbol, j), end='') time.sleep(delaySeconds)
import time lineLength = 20 delaySeconds = 0.05 frontSymbol = '=' frontSymbol2 = ['—', '\\', '|', '/'] backSymbol = ' ' for i in range(10): lineTmpla = "{:%s<%s} {} {:<2}"%(backSymbol, lineLength) for j in range(lineLength): tmpSymbol = frontSymbol2[j%(len(frontSymbol2))] print("\r" + lineTmpla.format(frontSymbol * j, tmpSymbol, j), end='') time.sleep(delaySeconds)
先科普下,"\r" 表示光标回到行首(参考自ascii编码表)。利用它就能达到覆盖字符的效果,但前提是别换行(消灭\n)。
来吧~ 看吾主的神迹。
再补充个进度条demo