os.system('cls') doesn't clear the screen in Pycharm?

假装没事ソ 提交于 2020-04-30 10:34:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!