progressbar - A simple command line progess bar
- Purpose:
This is a small class module which provides access to a simple console progress bar.
- Platform:
Linux/Windows | Python 3.6+
- Developer:
J Berendt
- Email:
- Comments:
n/a
- Example:
For a simple usage example, refer to the
ProgressBar
class docstring.
- class progressbar.ProgressBar(total_values: int = 25, bar_len: int = 25, symbol: str = '.', color: str = 'w')[source]
Implement a console progress bar into a processing loop.
- Parameters:
total_values (int, optional) – Total number of iterations. Defaults to 25.
bar_len (int, optional) – Complete length of the progress bar, in chars. Defaults to 25
symbol (str, optional) – The symbol which is used to track progress. Defaults to
'.'
.color (str, optional) – Colour of the progress bar; where only the first letter of the colour is required. Options are: red, green, yellow, blue, magenta, cyan, white. Defaults to ‘w’ (white).
- Design:
This is a simple console progress bar which should be called inside a processing loop.
On instantiation, you can pass in the bar colour, length and symbol parameters if you want to configure the appearance a little bit.
- Colour Options:
red, green, yellow, blue, magenta, cyan, white
- Example:
You might implement the progress bar in a loop like this:
>>> import time >>> from utils4.progressbar import ProgressBar >>> pb = ProgressBar(total_values=25, bar_len=25, symbol='#', color='red') >>> for i range(26): >>> # < some processing > >>> pb.update_progress(current=i) >>> # Optional pause to see updates. >>> time.sleep(.1) Processing 25 of 25 [ ......................... ] 100% Complete
- __init__(total_values: int = 25, bar_len: int = 25, symbol: str = '.', color: str = 'w')[source]
Progress bar class initialiser.
- update_progress(current: int)[source]
Incrementally update the progress bar.
- Parameters:
current (int) – Index value for the current iteration. This value is compared against the initialised
total_values
parameter to determine the current position in the overall progress.- Example:
Refer to the
ProgressBar
class docstring.