Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #64300
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Subject | Re: question about input() and/or raw_input() |
| Date | 2014-01-19 12:12 -0500 |
| Organization | IISS Elusive Unicorn |
| References | <roy-97803E.13302018012014@news.panix.com> <mailman.5690.1390080826.18130.python-list@python.org> <lbgtlo$87i$1@reader1.panix.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5710.1390151568.18130.python-list@python.org> (permalink) |
On Sun, 19 Jan 2014 16:14:48 +0000 (UTC), Grant Edwards
<invalid@invalid.invalid> declaimed the following:
>On 2014-01-18, Terry Reedy <tjreedy@udel.edu> wrote:
>> On 1/18/2014 1:30 PM, Roy Smith wrote:
>>> Pardon me for being cynical, but in the entire history of the universe,
>>> has anybody ever used input()/raw_input() for anything other than a
>>> homework problem?
>>
>> Homework problems (and 'toy' programs, such as hangman), whether in a
>> programming class or elsewhere, are one of the intended use cases of
>> Python. How else would you get interactive input without the complexity
>> of a gui?
>
>sys.stdin.readline()
At which point a simple:
nm = raw_input("Enter your name: ")
print "Hello, ", nm
turns into (to duplicate the behavior WRT line endings, and to minimize the
new features the student is exposed to)
import sys
sys.stdout.write("Enter your name: ")
nm = sys.stdin.readline()
nm.strip()
sys.stdout.write("Hello, ")
sys.stdout.write(nm)
sys.stdout.write("\n")
sys.stdout.flush()
Yes, a non-beginner would have been exposed to formatting operations
and been able to condense the three .write() calls into one... But the
assignment has gone from "learn how to do simple input and output" into
"learn about importable modules, learn how to handle line endings, and
maybe figure out simple I/O in all of that"
If that was the only route I'd rapidly end up creating a utility module
with, to start with, a simple <?>
import sys
def input(prompt=None):
if prompt:
sys.stdout.write(prompt)
return sys.stdin.readline().strip()
I rarely find a need to work at the sys.std*** level. Anything needing
that level of control is probably using a data file specified on the
command line and not interactive console...
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
question about input() and/or raw_input() Roy Smith <roy@panix.com> - 2014-01-18 13:30 -0500
Re: question about input() and/or raw_input() Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-18 18:41 +0000
Re: question about input() and/or raw_input() Emile van Sebille <emile@fenx.com> - 2014-01-18 10:49 -0800
Re: question about input() and/or raw_input() Peter Otten <__peter__@web.de> - 2014-01-18 20:05 +0100
Re: question about input() and/or raw_input() Terry Reedy <tjreedy@udel.edu> - 2014-01-18 16:33 -0500
Re: question about input() and/or raw_input() Grant Edwards <invalid@invalid.invalid> - 2014-01-19 16:14 +0000
Re: question about input() and/or raw_input() Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-01-19 12:12 -0500
Re: question about input() and/or raw_input() Grant Edwards <invalid@invalid.invalid> - 2014-01-19 17:42 +0000
Re: question about input() and/or raw_input() Chris Angelico <rosuav@gmail.com> - 2014-01-20 04:59 +1100
Re: question about input() and/or raw_input() Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-01-18 21:17 -0500
Re: question about input() and/or raw_input() Chris Angelico <rosuav@gmail.com> - 2014-01-19 13:46 +1100
Re: question about input() and/or raw_input() Rustom Mody <rustompmody@gmail.com> - 2014-01-18 20:15 -0800
Re: question about input() and/or raw_input() Chris Angelico <rosuav@gmail.com> - 2014-01-19 15:21 +1100
Re: question about input() and/or raw_input() Rustom Mody <rustompmody@gmail.com> - 2014-01-18 20:43 -0800
Re: question about input() and/or raw_input() Chris Angelico <rosuav@gmail.com> - 2014-01-19 15:59 +1100
Re: question about input() and/or raw_input() Rustom Mody <rustompmody@gmail.com> - 2014-01-19 00:26 -0800
Re: question about input() and/or raw_input() Chris Angelico <rosuav@gmail.com> - 2014-01-19 21:39 +1100
Re: question about input() and/or raw_input() Ethan Furman <ethan@stoneleaf.us> - 2014-01-19 08:14 -0800
Re: question about input() and/or raw_input() Chris Angelico <rosuav@gmail.com> - 2014-01-20 03:38 +1100
Re: question about input() and/or raw_input() Ethan Furman <ethan@stoneleaf.us> - 2014-01-19 09:50 -0800
Re: question about input() and/or raw_input() Chris Angelico <rosuav@gmail.com> - 2014-01-20 05:41 +1100
Re: question about input() and/or raw_input() Ethan Furman <ethan@stoneleaf.us> - 2014-01-19 11:16 -0800
Re: question about input() and/or raw_input() Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-19 06:24 +0000
Re: question about input() and/or raw_input() Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-19 18:07 +0000
Re: question about input() and/or raw_input() Grant Edwards <invalid@invalid.invalid> - 2014-01-19 18:15 +0000
Re: question about input() and/or raw_input() Roy Smith <roy@panix.com> - 2014-01-19 13:37 -0500
Re: question about input() and/or raw_input() Chris Angelico <rosuav@gmail.com> - 2014-01-20 05:43 +1100
Re: question about input() and/or raw_input() Grant Edwards <invalid@invalid.invalid> - 2014-01-19 19:11 +0000
Re: question about input() and/or raw_input() Gene Heskett <gheskett@wdtv.com> - 2014-01-19 15:09 -0500
Re: question about input() and/or raw_input() Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-19 19:17 +0000
Re: question about input() and/or raw_input() Larry Martell <larry.martell@gmail.com> - 2014-01-19 12:24 -0700
Re: question about input() and/or raw_input() Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-19 19:29 +0000
Re: question about input() and/or raw_input() Gene Heskett <gheskett@wdtv.com> - 2014-01-19 15:12 -0500
Re: question about input() and/or raw_input() Larry Martell <larry.martell@gmail.com> - 2014-01-19 13:22 -0700
csiph-web