python tqdm与print的冲突及解决方法 问题 原因 解决方法 第一种方法 第二种方法 问题 在开发fastnlp的过程中遇到以下问题:python中使用tqdm展示进度条,且同时打印一些输出时候会出现以下的情况: import sys import time from tqdm import tqdm for batch in tqdm(range(100), total=100, position=0, file=sys.stdout, desc="desc"): if batch % 5 == 0: print(batch) time.sleep(1) 原因 点击进入tqdm源码可以知道在__init__函数中有file的变量