Python 3 Print Update on multiple lines
<p>Is it possible to print and update more than one line?
This works for one line:</p>

<pre><code>print ("Orders: " + str(OrderCount) + " Operations: " + str(OperationCount), end="\r")
</code></pre>

<p>and get this: (Of course the numbers update because its in a loop)</p>

<pre><code>Orders: 25 Operations: 300
</code></pre>

<p>I have tried this:</p>

<pre><code>print ("Orders: " + str(OrderCount) + "\rOperations: " + str(OperationCount), end="\r\r")
</code></pre>

<p>and get this: (The number does update correctly)</p>

<pre><code>Operations: 300
</code></pre>

<p>Looking for two lines that are updated like:</p>

<pre><code>Orders: 25
Operations: 300
</code></pre>

<p>and not:</p>

<pre><code>Orders: 23
Operations: 298

Orders: 24
Operations: 299

Orders: 25
Operations: 300
</code></pre>

<p><code>\r</code> is a <em>carriage return</em>, where the cursor moves to the start of the line (column 0). From there, writing more text will overwrite what was written before, so you end up only with the last line (which is long enough to overwrite everything you've written before).</p>

<p>You want <code>\n</code>, a newline, which moves to the next line (and starts at column 0 again):</p>

<pre><code>print ("Orders: " + str(OrderCount) + "\nOperations: " + str(OperationCount), end="\n\n")
</code></pre>

<p>Rather than use <code>str()</code> and <code>+</code> concatenation, consider using string templating with <a href="https://docs.python.org/3/library/stdtypes.html#str.format" rel="nofollow"><code>str.format()</code></a>:</p>

<pre><code>print("Orders: {}\nOperations: {}\n".format(OrderCount, OperationCount))
</code></pre>

<p>Note that you <em>can't</em> go back up a line; if you wanted to use <code>\r</code> carriage returns to update two lines, then you are out of luck with straight-up printing. You'll need to switch to a full-terminal control with <a href="https://docs.python.org/3/howto/curses.html" rel="nofollow">Curses</a> or stick to putting everything on one line.</p>

<p>If you are going to go the Curses route, take into account that Windows compatibility is sketchy at best.</p>

python