yokome.util.progress
¶
-
class
yokome.util.progress.
ProgressBar
(iterable_len, *, bar_size=20, prefix=<function ProgressBar.<lambda>>, suffix=<function ProgressBar.<lambda>>, delimiter='r', end='n', file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>)¶ A progress bar.
Progress visualization can be done more than once for the same step by calling
print_current()
. The next step is visualized by callingprint_next()
.If the process is not completed, the delimiter is not written before the next step, so additional information can be written to the same line as the progress bar.
- Parameters
iterable_len (int) – A number indicating the progress state of the completed process.
bar_size – The width of the progress bar visualization, in numbers of characters.
prefix – A function that is called to construct the string prefix before the actual progress bar. Called with
i
andelement
as arguments.suffix – A function that is called to construct the string suffix after the actual progress bar. Called with
i
andelement
as arguments.delimiter (str) – The string to print after a line if the process was not completed.
end (str) – The string to print after a line if the process was completed.
file – The stream to which to print the line. Print to
sys.stdout
by default.
-
print_current
(element=None)¶ Print the progress bar at the current state of the process.
- Parameters
element – The element that corresponds to the state of the current process step. This is used in calls to the prefix and suffix functions.
-
print_next
(element=None)¶ Advance the process and print the progress bar at the new state of the process.
- Parameters
element – The element that corresponds to the state of the next process step. This is used in calls to the prefix and suffix functions.
-
yokome.util.progress.
print_bar
(i, element, iterable_len, *, bar_size, prefix=<function <lambda>>, suffix=<function <lambda>>, delimiter='\r', end='\n', file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>)¶ Print a progress bar.
- Parameters
i – A numeral between zero and
iterable_len
that indicates the state of progress. Espc. the index of an element in an iterable.element – The element in an iterable that corresponds to the progress state
i
.iterable_len – A numeral indicating the progress state of the completed process. Espc. the length of the iterable that contains
element
.bar_size – The width of the progress bar visualization, in numbers of characters.
prefix – A function that is called to construct the string prefix before the actual progress bar. Called with
i
andelement
as arguments.suffix – A function that is called to construct the string suffix after the actual progress bar. Called with
i
andelement
as arguments.delimiter (str) – The string to print after a line if the process was not completed.
end (str) – The string to print after a line if the process was completed.
file – The stream to which to print the line. Print to
sys.stdout
by default.
-
yokome.util.progress.
print_progress
(iterable, iterable_len=None, *, bar_size=20, prefix=<function <lambda>>, suffix=<function <lambda>>, delimiter='\r', end='\n')¶ Yield elements from an iterable, printing a progress bar before every step.
For an iterable with
n
elements,n + 1
steps are printed.- Parameters
iterable – The iterable to yield elements from.
iterable_len (int) – The length of
iterable
. IfNone
, dynamically determine the iterable length.bar_size – The width of the progress bar visualization, in numbers of characters.
prefix – A function that is called to construct the string prefix before the actual progress bar. Called with
i
andelement
as arguments while the process is not completed. Afterwards, called once with the length of the iterable andNone
.suffix – A function that is called to construct the string suffix after the actual progress bar. Called with
i
andelement
as arguments while the process is not completed. Afterwards, called once with the length of the iterable andNone
.delimiter (str) – The string to print after a line if the process was not completed.
end (str) – The string to print after a line if the process was completed.