More random python observations from a perl programmer

Tim Peters tim_one at email.msn.com
Wed Sep 15 01:19:51 EDT 1999


[Hrvoje Niksic]
>>> ...
>>> I don't see the purpose of raw_input() and input() when
>>> sys.stdin.readline() and eval(sys.stdin.readline()) are available.

[Tim]
>> Convenience;

[Hrvoje]
> My point exactly.

What, you're opposed to convenience <wink>?

> How often do you really need input()?  Using it to input numbers is
> wrong and potentially very dangerous, as shown before.

Oh, goodness -- I use input() routinely.  It's convenient <wink>.  Python is
used by all sorts of people for all sorts of things, and not every app (not
even most Python apps, I'd wager) need to worry about inventively malicious
users.  rexec and bastion are there for apps that need to worry (and if they
do so need, they have one hell of lot more to worry about than just input()
...).

> I think the additional verbosity of eval(sys.stdin.readline()) is a
> very good indication of what is really going on.

You're welcome to use that.  Note that it's missing input()'s optional
"prompt" feature, though -- less convenient.

>> similarly there's no "purpose" to print given that
>> sys.stdout.write() is also available.

> I find `print' very convenient.  I would find it more convenient if
> there were a way for it to print to stderr, though.

def err(*stuff):
    import sys, string
    msg = string.join(map(str, stuff))
    sys.stderr.write(msg)
    if msg[-1:] != "\n":
        sys.stderr.write("\n")

claim = "is"
err("This", claim, "convenient enough for me.")

apparently-stderr-doesn't-need-to-be-convenient-ly y'rs  - tim






More information about the Python-list mailing list