I am using anaconda on mac and I am wondering whether there is a way to clear my python command history. Specifically, upon calling python
in terminal, I wanted to clear anything I typed before here.
In an interactive shell/terminal, we can simply use ctrl+l to clear the screen.
The commands used to clear the terminal or Python shell are cls and clear.
Type python and hit enter to turn windows command prompt to python idle (make sure python is installed). Type quit() and hit enter to turn it back to windows command prompt. Type cls and hit enter to clear the command prompt/ windows shell.
Assuming you want to clear the command history Python goes through when you hit the up and down arrow keys, that history is managed by either the GNU readline library or libedit, depending on your system. The Python readline
module is the Python-level interface to the underlying library (even if that library is libedit), and on systems where the underlying library supports it, you can clear the history with readline.clear_history
:
>>> import readline
>>> readline.clear_history()
I do not know if the library on your Mac supports it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With