[Tutor] Other ways to use raw_input function

Wayne Werner waynejwerner at gmail.com
Tue Oct 18 20:09:11 CEST 2011


On Tue, Oct 18, 2011 at 12:58 PM, amt <0101amt at gmail.com> wrote:

> Greetings! I got stuck at an exercise from the book learn python the hard
> way about raw_input function.(exercise 11.2)
>
> After reading from docs.python.org I found out that this function can
> perform standard output without a trailing newline.Also it can take an input
> line, convert it as a string( stripping a trailing newline) and return it.
>
>
> The exercise question is : Can you find other ways to use it?
> <snip> Are there any other ways of using it? If yes can you please give me
> a detailed example so I can understand.
>

 The most common other way that I use it is on Windows. If you want the
terminal to stay open after your program has finished executing you can do
something like this:

# print_odds.py
# Prints some odd numbers

for x in xrange(1, 20, 2):
    print x

raw_input("Press <enter> to continue")



I've done similar things when debugging in a loop - instead of using print,
I use raw_input and it lets me see the output and waits for me to hit enter
to continue the loop.

HTH,
Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111018/8f51a94b/attachment.html>


More information about the Tutor mailing list