If it was possible to get output from this shell script into a variable I think that would be the ideal solution.
import os
os.system('read -s -n 1 -p "Press any key to continue..."')
I have a shell script that reacts to one keypress immediately (because "read" with the option "-n1" is selected) like this:
#!/bin/bash
read -s -n1 -p "" keypress
if test "$keypress" = "a"
then
open ~/something.txt
fi
if test "$keypress" = "b"
then
open ~/something_else.txt
fi
exit
How could I modify this to python 2 code to similarly react immediately to user input rather than waiting for the user to press return? (I use osx and would prefer a solution that only relies on the standard library, but anything that could work on both osx and linux would be fine.)
something=raw_input()
print "write a or b"
user_input_a='a'
user_input_b='b'
if something == user_input_a:
print 'it was a'
if something == user_input_b:
print 'it was b'