Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

Python Programming/Progress Bars

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

Progress bars in Python are abundant. There are several well-known packages for progress bars out there. External Progress Bars Some of the top bars are from the progress and the tqdm library. Progress progress Easy to use progress bars import progress.bar or import progress.spinner The progress module provides 7 different progress bars to use. They are: Bar ChargingBar FillingSquaresBar FillingCirclesBar IncrementalBar PixelBar ShadyBar The module also provides 6 spinners. These do not have a finish. They are: Spinner PieSpinner MoonSpinner LineSpinner PixelSpinner In order to access a bar/spinner, you run progress.a.b, where a is the type of indicator you want (bar or spinner) and b is the name of the bar/spinner. Furthermore, you have to import the module as progress.a or else it cannot see the bar/spinner. Example code import progress.bar import time b = progress.bar.Bar('Waiting', max = 100) for i in range(100): b.next() time.sleep(0.1) b.finish()We can also make it an iterator so we can put it into a for loop.from __future__ import print_function import progress.bar import time b = progress.bar.Bar('Printing', max = 26) letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] for letter in b.iter(letters): print(letter) time.sleep(0.1) b.finish() Tqdm tqdm Fast, Extensible Progress Meter The tqdm module relies off of one main class, the tqdm class. It has a GUI version, and a jupyter notebook-compatible version, and one for pandas. It will run as an iterator, a callable bar, and an action in a with statement. Basic Code from tqdm import tqdm adder = 1 sum = 0 for i in tqdm(range(100)): sum += adder