I have a workaround I've been using in production for 2 years. Not pretty, but works reliably. In your py script you call a batch file which gets a string of user input and writes it to a temp text file. Then python reads that file.
The batch file (getInput.bat):
@ echo off
REM Takes a single line of user input and writes it to an ascii file. More details below.
REM (See also getChoice.bat which takes a single keystroke and doesn't require "ENTER, control-Z and ENTER"
echo.
echo ==== GETINPUT.BAT =============================================
echo.
echo USER INPUT: respond with a line of text.
echo If you make a mistake, simply retype it -- this tool
echo saves just one line: the last _non-blank_ line entered.
echo.
echo To finish, press ENTER, control-Z and ENTER
echo.
echo.
echo *** %1
echo.
REM A blank input (eg: ^Z ENTER) leaves the output file unchanged, so
REM need to set a default string
SET USERINPUT=NULL
REM Closing the DOS window without input also leaves the output file unchanged, so need also
REM to overwrite the old file -- otherwise previous input is used. Note that the python
REM code below explicitly checks for "NULL"
echo NULL > B:\users\%username%\userinput.txt
REM Get userinput and send it to an environment variable.
FOR /F "tokens=*" %%A IN ('TYPE CON') DO SET USERINPUT=%%A
REM Send the value of the environment variable to a file, for python to read.
echo %USERINPUT% > B:\users\%username%\userinput.txt
The python code:
import getpass
import subprocess
username = getpass.getuser()
userInputFile = "B:/users/" + username + "/userinput.txt"
msgarg = "Type row and column of the Cell. Numbers only, separated by a space."
# (use doublequotes so CMD sees it as one argument)
# run the batch file -- which prompts for input and writes it to a temp file
subprocess.call([r"B:\software\utilities\getInput.bat",msgarg])
# read the user's input from that file
with open(userInputFile) as inputFile:
for line in inputFile:
if line:
userInput = line.rstrip()
break # stop at the first line read
if line == "NULL":
# do something to respond to NULL input, e.g. ...
print = "Aborting process based on user input (" + userInput + ")"