In Python, how to change text after it's printed?

后端 未结 5 734
名媛妹妹
名媛妹妹 2020-12-17 16:46

I have a Python program I am writing and I want it to be able to change text after it is printed. For example, let\'s say I want to print \"hello\" and erase one letter eve

5条回答
  •  一生所求
    2020-12-17 17:26

    Here's something that seems to work well:

    import time
    
    text = '\rgood-bye'
    for i in xrange(len(text), 0, -1):
        print text[0:i],
        time.sleep(1)
    print ' '
    

提交回复
热议问题