Python - ctrl L does not work

半腔热情 提交于 2019-12-10 17:46:02

问题


Attempting to use Ctrl+L for clearing Power Sheel in Python 2.7.8 I get no response.

Is there any problem in Windows 10?


回答1:


Ctrl+L only works on Linux/OS X terminals. It does not work on Windows. To clear the screen on Windows you could do the following:

import os
os.system('cls')



回答2:


To extend Kredns answer to Linux/OS X terminals as well:

import os
os.system('clear')



回答3:


I like Kredns's answer, however, you have to type all of that every time. I made a module/function. Okay, I am using Python 3.7.3, but similar answer for Python 2.

def cls():
    import os
    os.system('cls')
    return 

Save this as a script and import cls or whatever you want to call it. Import that (e.g. on python start up). So if you're in the correct directory:

from cls import cls

Then call it with cls() whenever you want to clear the screen.

cls()



回答4:


IdleX extension of IDLE has the functionality you are looking for. Try installing from here http://idlex.sourceforge.net/ OR https://pypi.org/project/idlex/

pressing CTRL-L, works in the intutive way (clear the console and take you to the top with a prompt, and doesn't clear the variables and definitions you have defined yet)



来源:https://stackoverflow.com/questions/42721491/python-ctrl-l-does-not-work

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