May 17, 2016

Console progress bar

It's very simple:

import sys
def update_progress(iteration, total):
    percent = int(iteration * 100.0 / total)
    sys.stdout.write(
        "\r[ {0:<51} ] {1}% ~{2}".format(
            '#' * (percent / 2), percent, iteration
        )
   )

The main trick is character "\r", which clear previous line.

No comments:

Post a Comment

New comment