Python - Readline Control-D after non-empty line does not work why?
<p>I am new to python, and I am sorry if what I am asking seems odd. I want to loop over each line on standard input and return a modified line to standard output immediately. I have code that works, mostly. However I do not know how to make this work completely.</p>

<p>I have the following code</p>

<pre><code>while True:
    line = sys.stdin.readline()

    if not line:
        break

    sys.stdout.write(line)
</code></pre>

<p>When being used interactively this will exit if there is an EOF on a new line, however if there is text before I type Control-D I must give the code twice before it will exit the line, and then once more before the loop will exit.</p>

<p>How do I fix this.</p>
