Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 Python打印语句不使用';无法用覆盖上一行\r\n_Python 2.7_Printing - Fatal编程技术网

Python 2.7 Python打印语句不使用';无法用覆盖上一行\r\n

Python 2.7 Python打印语句不使用';无法用覆盖上一行\r\n,python-2.7,printing,Python 2.7,Printing,我正在尝试覆盖Python2.7中的打印行 from __future__ import print_function import time print('This is the first statement', end='\r') time.sleep(1) print('This is the Second Statement') 从这一点上,我希望第一行打印出来,然后一秒钟后,第二行打印出来,覆盖第一行 当我执行代码时,我得到的只是脚本运行一秒钟后打印的第二行。这是怎么回事?如何使第

我正在尝试覆盖Python2.7中的打印行

from __future__ import print_function
import time
print('This is the first statement', end='\r')
time.sleep(1)
print('This is the Second Statement')
从这一点上,我希望第一行打印出来,然后一秒钟后,第二行打印出来,覆盖第一行


当我执行代码时,我得到的只是脚本运行一秒钟后打印的第二行。这是怎么回事?如何使第一条语句出现在第二条语句之前,然后覆盖?

使用
sys.stdout.flush

from __future__ import print_function
import time
import sys
print('This is the first statement', end='\r')
sys.stdout.flush() 
time.sleep(1)
print('This is the Second Statement')

所需冲洗背后的理论是什么?为什么其他打印操作不需要flush()?数据被缓冲调用flush将强制操作系统将其写入终端。影响它的是时间、睡眠。