If you don't want to do any fancy stuff on the command line beyond your example, you will have to redirect stdin to your terminal first thing in your python script. You can do that by invoking the command tty
from within Python and getting the path to your tty, then changing sys.stdin to that.
import sys, os
tty_path = os.popen('tty', 'r').read().strip() # Read output of "tty" command
sys.stdin = open(tty_path, 'r') # Open the terminal for reading and set stdin to it
I believe that should do what you want.
EDIT:
I was mistaken. This will fail for your use case. You need some way of passing the current TTY path to the script. Try this instead:
import sys, os
tty_path = os.environ['TTY']
sys.stdin = open(tty_path, 'r') # Open the terminal for reading and set stdin to it
But you must then invoke the script slightly differently:
TTY=`tty` python < source.py
I should add that I think the sanest way—avoiding this issue entirely—would be to not redirect the script to python's stdin at all and just invoke it with python source.py
.