overwriting output of function in terminal on same line
<p>I have a function, for example</p>

<pre><code>def f(x):
    for i in range(x):
        print i
</code></pre>

<p>Without making any addition in f(x) function, is it possible to overwrite the  terminal line during run? For example, in my case it shows like this:</p>

<pre><code>print f(5)
</code></pre>

<p>output is:</p>

<pre><code>1
2
3
4
</code></pre>

<p>but I want it to overwrite and instead print like this:</p>

<pre><code>print f(5)

4
</code></pre>

<p>Please keep in mind that I cannot modify inside f(x) function.</p>

<p>In general, no; but depending on what the "terminal" is assumed
to be, maybe.   Many terminal windows emulate the ancient cursor
positioning commands from one or more "glass tty" terminals. In
which case, if you assume you know what terminal is being emulated,
you can send cursor positioning commands to move back to the previous
before calling f.</p>

python python-2.7