Python multiple read on stdin cause it to block
Question: I am a student in programming school and need to complete a project playing
with financial stock's data.

I chose to do it in Python as it's the only language I played few days with
which is not taught in my school, I must be able to read on the standard input
and I am able to it once but not the second time, the program indefinitely
wait and I must stop it using ctrl+c raising an KeyboardInterrupt

Here is the code I get :

    
    
    #!/usr/bin/python                                                                                                                                                 
    from __future__ import print_function
    import sys
    
    if __name__ == "__main__":
        capital = int(sys.stdin.readline())
        days = int(sys.stdin.readline())
        initial = int(sys.stdin.readline())
        for day in range(days - 1):
        print("wait")
        try:
                value = int(sys.stdin.readline())
        except ValueError:
                break
    

Here is few hint about the input format I am getting.

First I get three numbers in three different lines at once. Then I get as many
input as the second number of the first input so I am looping on it.

As soon as I reach the

    
    
    sys.stdin.readline()
    

in the try/catch the program block and I have actually no idea about why this
is happening.


Answer: Instead of

    
    
    sys.stdin.readline()
    

use, in Python 2 (which I imagine you're using given the future-import)

    
    
    raw_input()
    

or, in Python 3,

    
    
    input()
    

I believe you may be running into buffering problems given your description of
your problems, and the `raw_input` and `input` built-in functions take all the
measures needed to avoid buffering problems, so you don't have to dig in at a
low level to fix things yourself.

