Home > Net >  Python console program, the ability to position text in the console
Python console program, the ability to position text in the console

Time:10-31

I wanted to write a short python console program that would retrieve the Btc price from bitbay and binance every 10 seconds. All in all, I wrote, but I would like the reading result to appear in the same place on the console all the time, and not to print a line under the line. Is there such a possibility in python? Because in C # it exists. I can't find such information anywhere, can anyone help and explain to me?

CodePudding user response:

Here is a short example using end='\r' in a for loop:

import time
for num in range(10):
    print(num, end='\r')
    time.sleep(1)

When you go to print the price, use the end='\r' argument. In this case, the output will show a single int at a time instead of showing all the numbers up to 10.

CodePudding user response:

In C#:

Console.Write("My text"   "\r");
Thread.Sleep(10000);
Console.Write("Next update"   "\r");
  • Related