Read and Write separately in python
<p>I'm trying to create a very simple program in python that needs to read input from the user and write output accordingly. I need an output similar to this:</p>

<pre><code>$./program.py
say something: Hello World
result: hello world
</code></pre>

<p>The thing is that i need to read input indefinitely, each time the user inputs data i would like that the printed data doesn't obstruct the input prompt. It will even better that no newlines be printed, keeping the output as above: a line for reading and another for writing.</p>

<p>I tried using curses but i don't want the hole screen to be used, just the two lines.</p>

<p>I believe this is what you want:</p>

<pre><code>import colorama
colorama.init()
no = 0
while True:
    user_input = str(raw_input('\033[2A'*no + '\033[KSay something: '))
    print '\033[KResult: ' + user_input
    no = 1
</code></pre>

<p>This how it looks after entering the string:</p>

<p><a href="http://i.stack.imgur.com/2sk8G.png" rel="nofollow"><img src="http://i.stack.imgur.com/2sk8G.png" alt="Working solution"></a></p>

<p>This implementation works on windows, however, if you use Linux, if I am not mistaken these are not necessary:</p>

<pre><code>import colorama
colorama.init() 
</code></pre>

<p>EDIT: Modified my code a bit so it does not overwrite the text that was printed before the execution of the code. Also added an image of working implementation.</p>

python terminal