拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...
不好意思,又是我。 再科普一个 "\b" 是退格的意思,它会向左移动一格并删除该格子上现实的字符,详情请参考ascii编码表
pythonimport sys, time def interface_show(**kwargs): lineTmpla = ' '*5 + kwargs['title'] + kwargs['artist'] + kwargs['rate'] + " %-3s" print time_remain(lineTmpla, kwargs['minutes']), def time_remain(lineTmpla, mins): count = 0 while (count < mins): count += 1 n = mins - count time.sleep(1) sys.stdout.write("\r" + lineTmpla %(n),) sys.stdout.flush() if not n: return 'completed' interface_show(title="倒计时demo", artist="哗嚓啊", rate="揍起来", minutes=5)
python
import sys, time def interface_show(**kwargs): lineTmpla = ' '*5 + kwargs['title'] + kwargs['artist'] + kwargs['rate'] + " %-3s" print time_remain(lineTmpla, kwargs['minutes']), def time_remain(lineTmpla, mins): count = 0 while (count < mins): count += 1 n = mins - count time.sleep(1) sys.stdout.write("\r" + lineTmpla %(n),) sys.stdout.flush() if not n: return 'completed' interface_show(title="倒计时demo", artist="哗嚓啊", rate="揍起来", minutes=5)
需要移动光标,在下暂时只知道 \b,有人知道其它并愿意告知的话就太感谢了
pythonimport sys, time def interface_show(**kwargs): print ' '*5, kwargs['title'], kwargs['artist'], kwargs['rate'], time_remain(kwargs['minutes']) def time_remain(mins): count = 0 length = len(str(mins)) sys.stdout.write(" " * length,) while (count < mins): count += 1 n = mins - count time.sleep(1) sys.stdout.write(('\b' * length) + str(n),) sys.stdout.flush() if not n: return 'completed' interface_show(title="倒计时demo", artist="哗嚓啊", rate="揍起来", minutes=5)
import sys, time def interface_show(**kwargs): print ' '*5, kwargs['title'], kwargs['artist'], kwargs['rate'], time_remain(kwargs['minutes']) def time_remain(mins): count = 0 length = len(str(mins)) sys.stdout.write(" " * length,) while (count < mins): count += 1 n = mins - count time.sleep(1) sys.stdout.write(('\b' * length) + str(n),) sys.stdout.flush() if not n: return 'completed' interface_show(title="倒计时demo", artist="哗嚓啊", rate="揍起来", minutes=5)
不好意思,又是我。
再科普一个 "\b" 是退格的意思,它会向左移动一格并删除该格子上现实的字符,详情请参考ascii编码表
办法无非就两个
1) 整行覆盖。
2) 局部覆盖
需要移动光标,在下暂时只知道 \b,有人知道其它并愿意告知的话就太感谢了