Using Readline In Python REPL On Windows With PyReadline and PtPython#
When you search on Internet, you will find many tutorials telling you to install a Python module called readline, but unfortunately, it's not compatible on Windows OS :
On Windows, the counterpart is PyReadline, install it by :
Here are the features of PyReadline : - keyboard text selection and copy/paste - Shift-arrowkeys for text selection - Control-c can be used for copy activate with allow_ctrl_c(True) in config file - Double tapping ctrl-c will raise a KeyboardInterrupt, use ctrl_c_tap_time_interval(x) where x is your preferred tap time window, default - 0.3 s. - paste pastes first line of content on clipboard. - ipython_paste, pastes tab-separated data as list of lists or numpy array if all data is numeric - paste_mulitline_code pastes multi line code, removing any empty lines.
As PyReadline must be used inside Python REPL, you need to type
import PyReadline from the very beginning of the Python REPL. To be a lazy devops, just add the import into a file and let Python to source it before the first prompt is displayed by using $env:PYTHONSTARTUP :
Previous chapter mentioned that PyReadline is no more maintained, so here comes the PtPython.
Install PtPython by :
Start it by typing simply :
ptpython from the terminal, it will start a Python REPL with prompt_toolkit integrated, nothing to set on $env:USERPROFILE