Overwriting/clearing previous console line

前端 未结 2 1343
小鲜肉
小鲜肉 2021-01-18 01:40

My problem is, that I want to be able to overwrite/clear previous printed line in python console. This question has been asked many times (Python - Remove and Replace Printe

2条回答
  •  离开以前
    2021-01-18 02:05

    You're trying to use ANSI escape sequences to move the cursor. Windows doesn't support those by default. To enable them, you could install the colorama module with pip install colorama in your terminal, then in Python:

    import colorama
    colorama.init()
    

    If you've upgraded to Windows 10, you can enable support with this instead:

    import ctypes
    kernel32 = ctypes.windll.kernel32
    kernel32.SetConsoleMode(kernel32.GetStdHandle(-11), 7)
    

    (Source: https://stackoverflow.com/a/36760881/6379747)

提交回复
热议问题