def tqdm_callback(N, notebook=True):
"""
Return a :module:`tqdm` progress bar expecting *N* iterations,
either suitable with jupyter if *notebook* is true and for the
terminal otherwise. The progress bar includes an additional method
:function:`callback` (function of one ignored parameter) meant to
be past as a callback function called to update the progress bar.
"""
if notebook:
progress_bar = tqdm.tqdm_notebook(total=N)
else:
progress_bar = tqdm.tqdm(total=N)
def callback(self, i):
self.update()
progress_bar.callback = partial(callback, progress_bar)
return progress_bar
评论列表
文章目录