[Edu-sig] The fate of raw_input() in Python 3000

kirby urner kirby.urner at gmail.com
Fri Sep 15 23:27:04 CEST 2006


On 9/15/06, John Posner <jjposner at snet.net> wrote:

> (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.
>

Hmmmm, didn't know about that difference (I still haven't read the
original PEP -- knowing the work is already done reduces my curiosity
level).

There *is* this strong "everything is a file" metaphor (predates
"everything is an object") that makes us *want* to see stdin as "just
another file" (why it's satisfying to have the same readline() in both
the sys.stdin and open('file') contexts.

> (2) ... would impose yet another trap for beginning users to fall into.

What's all this fascination with keeping beginners out of traps?  Fall
in a few times, learn from the experience, brush off and move on.

I'm all for pandering to beginners, but they're not entitled to prima
donna treatment, any more than their teachers.  Real work needs doing.
 The needs of beginners take a back seat.

The needs of 1970s-trained CS teachers take a back seat also.

Anyway, my point is you don't teach beginners by raw_input heavy
prompting, you teach them by showing them how to:

(a) explore the source code without running it (with help and dir)

(b) look for the little functions and classes it contains

(c) import the ones that look safe and feed them through their
standard APIs as callables, and/or dot-trigger them (basic shell
operations -- what beginners should start with).

If there's no source code included, think twice about running it.  Who
thinks they have a right to run on your CPU leaving you out of the
loop?  Authenticate the source at least.  I mostly trust MSFT, but I
still prefer the kinds of protections the bazaar affords (e.g. I'd
never trust USA elections if the core voting code was anything but
wide open to public scrutiny).

If there's a lot of raw_input, you're likely dealing with 1970s era
stuff -- so be careful (CP4E was still pretty weak back then).

> ("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

Just go

a = sys.stdin.readline()[:-1]  # because you didn't mean to include /n

?

Kirby


More information about the Edu-sig mailing list