[Edu-sig] The fate of raw_input() in Python 3000
John Posner
jjposner at snet.net
Fri Sep 15 22:56:07 CEST 2006
My apologies if someone else has already pointed out this difference between
sys.stdin.readline() and raw_input(): they return different strings.
>>> a = sys.stdin.readline()
spam
>>> b = raw_input()
spam
>>> a
'spam\n'
>>> b
'spam'
IMHO, that trailing NL character ...
(1) ... indicates the fact that these two functions were really designed for
different purposes: getting data from a file vs. getting data interactively
from a person.
(2) ... would impose yet another trap for beginning users to fall into.
("Teacher, I typed in 'Richard', but Python doesn't seem to think I did.")
Sure, we can try to sell strip() to the student, but I wouldn't blame
him/her for suspecting that Python is so dumb that it doesn't distinguish
between the content of a message and the gesture than ends the message.
-John Posner
More information about the Edu-sig
mailing list