When writing carriage return to a pycharm console the whole line is deleted?

前端 未结 3 1993
暖寄归人
暖寄归人 2020-12-11 07:13

I have a program in Python that makes extensive use of the line feed character to produce the effect of an updating console line (specifically a progress bar).

When

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-11 07:23

    Be careful with short time between prints and short length of printed strings, printing can be tricky and print few values in one row.

    To workaround that you can add second \r after white character:

    for i in range(10):
        print("\r \r{0}".format(str(i)), end='')
        time.sleep(0.1)
    

    My solution for similar issue: https://stackoverflow.com/a/44524422/6857902

提交回复
热议问题