Home > python > rlwrap: adding keyboard editing functionalities to your scripts

rlwrap: adding keyboard editing functionalities to your scripts

Problem
You have an interactive script that waits for some user input, similarly to the (Python) shell. In bash, you can use the arrow keys for editing / browsing, but it’s not available in a Python script right away. If you read the user input with raw_input() for instance, you cannot move the cursor back with the left arrow, or you cannot browse previous commands with the up arrow.

And still… How to add such bash-like functionalities to your script? The method must be absolutely painless, of course.

Solution
Use the command “rlwrap“, which magically adds these functionalities to any script. Awesome. So instead of launching your script with “./something.py“, launch it like this:

$ rlwrap something.py

You might have to install rlwrap with “sudo apt-get install rlwrap“. More info about rlwrap: here.

Categories: python Tags: , , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: