progressbar#

progressbar(i=None, maxiters=None, label='', every=1, length=30, empty='—', full='•', newline=False, flush=False, **kwargs)[source]#

Show a progress bar for a for loop.

It can be called manually inside each iteration of the loop, or it can be used to wrap the object being iterated. In the latter case, it acts as an alias for the tqdm.tqdm() progress bar.

Parameters:
  • i (int/iterable) – current iteration (for text output), or iterable object (for tqdm)

  • maxiters (int) – maximum number of iterations (can also use an object with length)

  • label (str) – initial label to print

  • every (int/float) – if int, print every “every”th iteration (if 1, print all); if float and <1, print every maxiters*every iteration

  • length (int) – length of progress bar

  • empty (str) – character for not-yet-completed steps

  • full (str) – character for completed steps

  • newline (bool) – whether to print each iteration on a new line

  • flush (bool) – whether to force-flush the buffer

  • kwargs (dict) – passed to tqdm.tqdm(); see its documentation for full options

Examples:

# Direct usage inside a loop
for i in range(20):
    sc.progressbar(i+1, 20)
    sc.timedsleep(0.05)

# Direct usage inside a loop with custom formatting
for i in range(1000):
    sc.progressbar(i+1, 1000, every=100, length=10, empty=' ', full='✓', newline=True)
    sc.timedsleep(0.001)

# Used to wrap an iterable, using tqdm
x = np.arange(100)
for i in sc.progressbar(x):
    plt.pause(0.01)

Adapted from example by Greenstick (https://stackoverflow.com/questions/3173320/text-progress-bar-in-the-console)

New in version 1.3.3: “every” argument
New in version 3.0.0: wrapper for tqdm