Skip to content

Instantly share code, notes, and snippets.

@RyanMillerC
Forked from aubricus/License
Last active May 14, 2018 17:28

Revisions

  1. RyanMillerC revised this gist May 8, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions ProgressBar.py
    Original file line number Diff line number Diff line change
    @@ -12,6 +12,7 @@ def __init__(
    ):
    """Initialize instance and print process bar at 0 percent
    completed.
    :param int total:
    Total number of cycles to iterate through.
    :param int iterator:
    @@ -47,5 +48,4 @@ def update(self):
    if self.iterator == self.total:
    sys.stdout.write('\n')
    sys.stdout.flush()

    self.iterator += 1
    self.iterator += 1
  2. RyanMillerC revised this gist May 7, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions ProgressBar.py
    Original file line number Diff line number Diff line change
    @@ -23,6 +23,7 @@ def __init__(
    :param int decimals:
    Round percent shown to this decimal place.
    :param int bar_length:
    Display length of progress bar.
    """
    self.bar_len = bar_length
    self.decimals = decimals
  3. RyanMillerC revised this gist May 7, 2018. 2 changed files with 50 additions and 25 deletions.
    50 changes: 50 additions & 0 deletions ProgressBar.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    # -*- coding: utf-8 -*-

    import sys

    class ProgressBar():
    """Printable progress bar.
    """

    def __init__(
    self, total, iterator=0, prefix='Progress',
    suffix='Completed', decimals=1, bar_length=50
    ):
    """Initialize instance and print process bar at 0 percent
    completed.
    :param int total:
    Total number of cycles to iterate through.
    :param int iterator:
    Current cycle. Typically leave at default value.
    :param str prefix:
    Text to prepend before progress bar.
    :param str suffix:
    Text to append after progress bar.
    :param int decimals:
    Round percent shown to this decimal place.
    :param int bar_length:
    """
    self.bar_len = bar_length
    self.decimals = decimals
    self.iterator = iterator
    self.prefix = prefix
    self.suffix = suffix
    self.total = total
    self.update()

    def update(self):
    """Update progress bar. Call once per cycle.
    """
    str_format = "{0:." + str(self.decimals) + "f}"
    percents = str_format.format(100 * (self.iterator / float(self.total)))
    f_length = int(round(self.bar_len * self.iterator / float(self.total)))
    bar = '█' * f_length + '-' * (self.bar_len - f_length)

    sys.stdout.write('\r%s |%s| %s%s %s'
    %(self.prefix, bar, percents, '%', self.suffix))

    if self.iterator == self.total:
    sys.stdout.write('\n')
    sys.stdout.flush()

    self.iterator += 1
    25 changes: 0 additions & 25 deletions print_progress.py
    Original file line number Diff line number Diff line change
    @@ -1,25 +0,0 @@
    # -*- coding: utf-8 -*-

    # Print iterations progress
    def print_progress(iteration, total, prefix='', suffix='', decimals=1, bar_length=100):
    """
    Call in a loop to create terminal progress bar
    @params:
    iteration - Required : current iteration (Int)
    total - Required : total iterations (Int)
    prefix - Optional : prefix string (Str)
    suffix - Optional : suffix string (Str)
    decimals - Optional : positive number of decimals in percent complete (Int)
    bar_length - Optional : character length of bar (Int)
    """
    str_format = "{0:." + str(decimals) + "f}"
    percents = str_format.format(100 * (iteration / float(total)))
    filled_length = int(round(bar_length * iteration / float(total)))
    bar = '█' * filled_length + '-' * (bar_length - filled_length)

    sys.stdout.write('\r%s |%s| %s%s %s' % (prefix, bar, percents, '%', suffix)),

    if iteration == total:
    sys.stdout.write('\n')
    sys.stdout.flush()
  4. @aubricus aubricus created this gist Nov 3, 2016.
    25 changes: 25 additions & 0 deletions print_progress.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    # -*- coding: utf-8 -*-

    # Print iterations progress
    def print_progress(iteration, total, prefix='', suffix='', decimals=1, bar_length=100):
    """
    Call in a loop to create terminal progress bar
    @params:
    iteration - Required : current iteration (Int)
    total - Required : total iterations (Int)
    prefix - Optional : prefix string (Str)
    suffix - Optional : suffix string (Str)
    decimals - Optional : positive number of decimals in percent complete (Int)
    bar_length - Optional : character length of bar (Int)
    """
    str_format = "{0:." + str(decimals) + "f}"
    percents = str_format.format(100 * (iteration / float(total)))
    filled_length = int(round(bar_length * iteration / float(total)))
    bar = '█' * filled_length + '-' * (bar_length - filled_length)

    sys.stdout.write('\r%s |%s| %s%s %s' % (prefix, bar, percents, '%', suffix)),

    if iteration == total:
    sys.stdout.write('\n')
    sys.stdout.flush()