[Tutor] read from standard input

Andrei Petre andrei.petre at gmail.com
Thu Feb 14 03:57:36 CET 2008


Hello,

I want to read from the standard input numbers until i reach a certain value
or to the end of the "file".
What is the simplest, straightforward, pythonic way to do it?

a sketch of how i tried to do it:
[code]
while 1 < 2:
    x = raw_input()
    if type(x) != int or x == 11:
        break
    else:
        print x
[/code]

but don't work. and i'm interest in a general way to read until it is
nothing to read.


to ilustrate that in C:
[code]
int x;
while( scanf("%d",&x) == 1 && x != 11)
             printf("%d\n", x);
[/code]


Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080214/44cef5a9/attachment.htm 


More information about the Tutor mailing list