Last active
June 25, 2018 23:03
-
-
Save lexdene/5804289 to your computer and use it in GitHub Desktop.
Python在同一行输出内容。 原理: 输出\r \r的作用是回到一行的开头
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
''' | |
Python在同一行输出内容。 | |
原理: | |
输出\r | |
在Linux中,\r的作用是回到一行的开头。 | |
这里不能使用print,因为print自带换行。而这里我们不能使用换行。 | |
但是如果禁用print的换行也不行。如果没有换行print就不会flush,导致什么也不输出。 | |
''' | |
import time | |
import sys | |
for i in range(100): | |
sys.stdout.write('\r%d' % i) | |
sys.stdout.flush() | |
time.sleep(0.1) | |
print '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
想问一下在cpp里面怎么实现?flush好像不太能用...