You can redirect your stdin to a file and then raw_input() will read from that file.
Example -
def run(): import sys f1 = sys.stdin f = open('input.txt','r') sys.stdin = f get_name() f.close() sys.stdin = f1
Please note: after you do - f = open('input.txt','r') and sys.stdin = f , raw_input () will read from the file <filename> .
Once you are done with get_name (), close the file and restore stdin with sys.stdin = sys.__stdin__ if you want to restore it back to console input, otherwise you can restore it to f1 , which will restore it to a state that was before the test.
Note that you must be careful when redirecting input.
Anand s kumar
source share