0

I have three progress bars in my code(1 main progress bar and 2 sub progress bars). I need to display those progress bars one by one in a new line.

I have tried including the new line inside the function but that is creating a new line for every iteration which will not look good.


        #Progress Bar
    def progress(count, total, status=''):
            bar_len = 40
            filled_len = int(round(bar_len * count / float(total)))

            percents = round(100.0 * count / float(total), 1)
            bar = '=' * filled_len + '-' * (bar_len - filled_len)

            sys.stdout.flush()
            sys.stdout.write('\r[%s] %s%s - %s\r' % (bar, percents, '%', status))

            sys.stdout.flush()
            sys.stdout.write("\r")

    def sub_progress_source(count, total, status=''):
            bar_len = 40
            filled_len = int(round(bar_len * count / float(total)))

            percents = round(100.0 * count / float(total), 1)
            bar = '=' * filled_len + '-' * (bar_len - filled_len)

            sys.stdout.flush()
            sys.stdout.write('\r\n\t[%s] %s%s - %s\r' % (bar, percents, '%', status))

            sys.stdout.flush()
            sys.stdout.write("\r")

    def sub_progress_target(count, total, status=''):
            bar_len = 40
            filled_len = int(round(bar_len * count / float(total)))

            percents = round(100.0 * count / float(total), 1)
            bar = '=' * filled_len + '-' * (bar_len - filled_len)
            sys.stdout.flush()
            sys.stdout.write('\r\n\t[%s] %s%s - %s\r' % (bar, percents, '%', status))    
            sys.stdout.flush()
            sys.stdout.write("\r")
[====------](Main Progress Bar)
    [====-----](Sub Progress Bar 1)
    [=======--](Sub Progress Bar 2)

1 Answers1

0

To overwrite multiple lines in the console, you need libraries like curses (unix based systems) or win32 console api (windows)

Take a look this this answer and following answers on that page to find out more.

Btw you are using way too many '\r' and std.flushes which results in the weird output you are getting :D

Patrick_Weber
  • 120
  • 1
  • 9