python实现原地刷新方式输出-可用于百分比进度显示输出

方式1:

import sys

sys.stdout.write('\r' + '你的输出详情')
sys.stdout.flush()

方式2:

print('\r' + '你的输出详情', end='', flush=True)

实例:

import sys
import time

for i in range(101):
    # 方式1
    sys.stdout.write('\r' + str(i))
    sys.stdout.flush()
    # 方式2
    print('\r' + str(i), end='', flush=True)

    time.sleep(0.3)

猜你喜欢

转载自www.cnblogs.com/007sx/p/9420443.html