a similar question has been asked before, but the answers suggested a workaround which is not applicable to my situation.
An email message is piped from mutt to a script, and is read from STDIN:
message = sys.stdin.read()
# message is parsed and URLs are printed as a list to choose from...
selected_index = raw_input('Which URL to open?')
I understand that raw_input() will get the EOF left by read(), but is there a way to 'reset' STDIN?
Python raw_input function is used to get the values from the user. We call this function to tell the program to stop and wait for the user to input the values.
The NameError: name 'raw_input' is not defined error is raised when you try to use the raw_input() method in Python 3. To fix this error, replace all instances of raw_input() with the input() function in your program.
a = input() will take the user input and put it in the correct type. Eg: if user types 5 then the value in a is integer 5. a = raw_input() will take the user input and put it as a string. Eg: if user types 5 then the value in a is string '5' and not an integer.
Have you tried this:
message = sys.stdin.read()
sys.stdin = open('/dev/tty')
selected_index = raw_input('Which URL to open?')
This works on Linux; maybe it will work for OSX too.
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