pythoncarriage-returnterminator

carriage return not working in Terminator but works fine in Terminal in Ubuntu


I am using '\r' in print function in python 2.7. It works fine in terminal but not in terminator.


For example:

I am using a decrement counter which decrements from n to 0. In the Terminal, the count values are updated at the same line while in terminator, it count values get printed on new line. I am using terminator for various reasons such as its advanced features like tab partitioning etc. Below is the code snapshot

import sys
import time

if __name__ == "__main__":

    sleep_time_in_sec = 15
    time_to_go_back_mns = 10

    for remaining in range(sleep_time_in_sec, -1, -1):
        sys.stdout.write("\r")
        sys.stdout.write(
            "{:2d} seconds remaining to read last {:2d} minutes of data and perform prediction .....".format(remaining,
             time_to_go_back_mns))
        sys.stdout.flush()
        time.sleep(1)

Can someone please suggest a fix


Solution

  • The answer for this post goes to @Rick van Lieshout.


    In my case, I was using multiple tabs in the same window as a result of which \r was not working. It worked fine when I used it in a separate window or a tab with full horizontal width.