
March 13th, 2004, 02:29 AM
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 5
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
Re: comparing user input against a string (newbie)
I believe the problem is that sys.stdin.readline() will read in the whole line, including the carriage return ("\n") at the end. According to the Python docs:
Quote: readline( [size])
Read one entire line from the file. A trailing newline character is kept in the string (but may be absent when a file ends with an incomplete line). |
If you wish to remove the newline character try rstrip(). Here's your code modified to (hopefully) work:
Code:
while 1:
print "Pls input the nominated text: "
ui = sys.stdin.readline()
ui = ui.rstrip("\n")
if ui=="q":
break
|