问题
I use os.system('cls')
in Pycharm to clear the screen from what has been printed before. However, when running the code, it does not clear the formerly printed stuff, and instead prints an upward arrow at the end. What can the problem be?
回答1:
PyCharm's emulation of the Windows system console isn't 100%. Neither is any IDE's. Try that in IDLE or PythonWin, and you will see that it also does something other than you might expect from the Windows console.
This behaviour is by design. Bear in mind that most real-world Python interactive applications do not interact with their users via input()
and print()
calls.
If you want your output to behave exactly like the Windows console then send your output to the Windows console.
回答2:
In the current version of PyCharm on Linux it is possible to use os.system("clear")
. You have to edit the 'Run/Debug Configuration' and tick the box 'Emulate terminal in output console'.
I assume it works on Windows with os.system("cls")
as well.
来源:https://stackoverflow.com/questions/56306486/os-systemcls-doesnt-clear-the-screen-in-pycharm