Skip to content
Advertisement

How to output above the last printed line?

Is there a way in python to print something in the command line above the last line printed? Or, similarly to what I want to achieve, remain the last line intact, that is, not overwrite it.

The goal of this is to let the last line in the command line a status/precentage bar.

Output example:

JavaScript

Next refresh:

JavaScript

Next refresh:

JavaScript

Advertisement

Answer

JavaScript

Works in my python 3.4, final output is:

JavaScript

If you want read more about terminal escape codes see: Wikipedia’s ANSI escape codes article.

As requested, example with a space:

JavaScript

The final output is:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement