sys.stdout.write('\b') # move back the cursor
sys.stdout.write(' ') # write an empty space to override the
# previous written character.
sys.stdout.write('\b') # move back the cursor again.
# Combining all 3 in one shot:
sys.stdout.write('\b \b')
# In case you want to move cursor one line up. See [1] for more reference.
sys.stdout.write("\033[F")
使用print()时,可以将end设置为\r,这将用新文本替换行中的文本。
只是为了说明@user590028和@Kimvais给出的伟大答案
参考资料 [1] This answer by Sven Marnachin in Python Remove and Replace Printed Items
[2] Blog post about building progress bars
相关问题 更多 >
编程相关推荐