question about input() and/or raw_input()

Chris Angelico rosuav at gmail.com
Sun Jan 19 05:39:50 EST 2014


On Sun, Jan 19, 2014 at 7:26 PM, Rustom Mody <rustompmody at gmail.com> wrote:
> If you want to give an irrelevant example at least give a correct one :D
> the difference between str and hex is an arcane difference (Ive never used hex)
> the difference between functions and procedures is absolutely basic.

They don't give the same result for every possible input, any more
than your two do:

>>> foo(1.234567890123456)
2.23456789012
>>> bar(1.234567890123456)
2.234567890123456

(Tested on 2.7.3 on Linux. YMMV.)

There's no difference in Python between functions and procedures. It's
all functions, and some of them implicitly return None. If there were
a difference, what would this be?

def none_if(value, predicate):
    if not predicate(value): return value

Personally, I'm quite happy with Python and the print function. (Or
statement, if you prefer. Same difference.) The most fundamental
aspects of any program are input, output, and preferably some
computation in between; and the most fundamental forms of input are
the command line / console and the program's source, and the most
basic output is the console. So the most basic and obvious program
needs:

1) Access to the command-line arguments
2) The ability to read from the console
3) Some means of writing to the console.

Not every program will need all that, but they'd be the most obvious
and simplest methods of communication - especially since they're the
three that are easiest to automate. How do you run a GUI program
through automated testing? With difficulty. How do you run a stdio
program through automated testing? Pipe it some input and compare its
output to the standard. And that means people should be accustomed to
using print, and sys.argv, and (raw_)input.

Fortunately Python doesn't have ob_start() / ob_get_clean() to tempt
people to use print when they should use return. So there's no
problem.

ChrisA



More information about the Python-list mailing list