PyCharm print end='\r' statement not working

后端 未结 2 1164
耶瑟儿~
耶瑟儿~ 2021-02-13 03:25

There are already lots of other questions about the print statement, but I have not found an answer to my problem:

When I do:

for idx in range(10):
    p         


        
2条回答
  •  遥遥无期
    2021-02-13 03:54

    I had the same issue. While a solution using print() has eluded me, I have found sys.stdout.write works fine. (Win10, Python 3.5.1, Pycharm 2016.3.2)

    import sys
    import time
    
    def countdown(n):
        for x in reversed(range(n)):
            sys.stdout.write('\r' + str(x))
            time.sleep(1)
    
    countdown(60)
    

提交回复
热议问题