Blog

Reading keyboard input with Python

There are a number of ways to read keyboard input with python. One easy option is to use the curses library, using the getch() method, as shown below: The program above initialises the curses library, then sits in an infinite loop, printing a message whenever any keyboard buttons are pressed. Use ctrl-c to interrupt the loop and clean up curses before exiting gracefully. Note that …

Start reading Reading keyboard input with Python

Convert a delimited string into an array in Bash

If you’ve got a string of items in bash which are delimited by a common character (comma, space, tab, etc) you can split that into an array quite easily. Simply (re)define the IFS variable to the delimiter character and assign the values to a new variable using the array=($<string_var>) syntax. The new variable will now be an array of …

Start reading Convert a delimited string into an array in Bash