This topic created in 4028 days ago, the information mentioned may be changed or developed.
就比如像下面这种循环结果,倒计时
``` python
count = 0
b = 60
while (count < b):
count += 1
n = b - count
print n
time.sleep(1)
```
如果覆盖上一次print的结果
7 replies • 2015-05-31 09:29:22 +08:00
 |
|
2
jedyu May 29, 2015
\b 回到行首
|
 |
|
3
LeoQ May 29, 2015 via Android
clear能用么
|
 |
|
4
Sylv May 29, 2015
import sys import time
print '1', sys.stdout.flush() # 输出缓存 time.sleep(1) print '\r', # 回车符回到行首 print '2',
|
 |
|
5
lzachilles May 29, 2015
cnt = 1 while True: cnt += 1 print cnt, print '\r',
|
 |
|
7
cc7756789 May 31, 2015
搞定但是先问题无法解决,就是倒计时输出会在最左边输出,如何把它禁锢在指定的区域呢? ``` def interface_show(**kwargs): print ' '*5, kwargs['title'], kwargs['artist'], kwargs['rate'], time_remain(kwargs['minutes'])
def time_remain(mins): count = 0 while (count < mins): count += 1 n = mins - count time.sleep(1) sys.stdout.write("%d \r" % n,) sys.stdout.flush() if not n: return 'completed' ```
最后输出这样的信息,最右边的是总时长,最左边的是倒计时效果。 108 <旅立ち(「はるかな旅」ストリングス·ヴァージョン)> 吉田潔 ★★★★ 205
|