In Chapter 7, Fuzzy Hashing, we used the progressbar
module to track program progress for the user. And while the progressbar
module allows us to create a finely tuned progress bar, we can accomplish the same task in one line of code with tqdm
. The tqdm
module (version 3.4.0
) can create a progress bar with any Python iterator.
In the preceding example, we wrap an iterator created by range(100)
around tqdm
. That alone creates the progress bar displayed in the image. An alternative method, using the trange()
function, makes our task even simpler. We will use this module to create a progress bar for processing each WAL frame.
The following code creates the same progress bar as shown in the previous image. The trange()
is an alias for tqdm(xrange())
and makes creating a progress bar even simpler.
>>>from tqdm import trange >>> from time import sleep >>> for x in trange(100): ... sleep(1)