[Tutor] Communicating Between Programs Using Raw Inputs (con'd)

Alan Gauld alan.gauld at btinternet.com
Sun Jun 19 01:55:26 CEST 2011


"Jacob Bender" <benderjacob44 at gmail.com> wrote

> *Lock.py: *
> 
> password = "a"
> psswd_try = raw_input("What's the password? ")
> 
> if psswd_try == password:
>    print "correct!!!"
>    raw_input()
> else:
>    print "wrong"
>    raw_input()
> *
> Key.py*:
> 
> import sys
> sys.stdout.write("a")
> 
> And all went well except for an EOF error caused 
> by the raw_input inside the "if" statement in my 
> Lock program. However I did get it to print "correct",

You ask for two inputs but only provide one, so 
you get an error. The Key.py program closes stdout 
(which is Lock.py's stdin)  before Lock.py gets any 
second input. 

Add another print(or sys.stdout.write() ) to Key.py
and see how you get on.

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list