本文整理匯總了Python中tqdm.tqdm.auto方法的典型用法代碼示例。如果您正苦於以下問題:Python tqdm.auto方法的具體用法?Python tqdm.auto怎麽用?Python tqdm.auto使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tqdm.tqdm
的用法示例。
在下文中一共展示了tqdm.auto方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _download
# 需要導入模塊: from tqdm import tqdm [as 別名]
# 或者: from tqdm.tqdm import auto [as 別名]
def _download(url: str, path: Path):
try:
import ipywidgets
from tqdm.auto import tqdm
except ModuleNotFoundError:
from tqdm import tqdm
from urllib.request import urlretrieve
path.parent.mkdir(parents=True, exist_ok=True)
with tqdm(unit='B', unit_scale=True, miniters=1, desc=path.name) as t:
def update_to(b=1, bsize=1, tsize=None):
if tsize is not None:
t.total = tsize
t.update(b * bsize - t.n)
try:
urlretrieve(url, str(path), reporthook=update_to)
except Exception:
# Make sure file doesn’t exist half-downloaded
if path.is_file():
path.unlink()
raise
示例2: __init__
# 需要導入模塊: from tqdm import tqdm [as 別名]
# 或者: from tqdm.tqdm import auto [as 別名]
def __init__(self, frontend="auto", **kwargs):
"""
Parameters
----------
frontend : {"auto", "console", "gui", "notebook"}, optional
Selects a frontend for displaying the progress bar. By default ("auto"),
the frontend is chosen by guessing in which environment the simulation
is run. The "console" frontend displays an ascii progress bar, while the
"gui" frontend is based on matplotlib and the "notebook" frontend is based
on ipywidgets.
**kwargs : dict, optional
Arbitrary keyword arguments for progress bar customization.
See https://tqdm.github.io/docs/tqdm/.
"""
if frontend == "auto":
from tqdm.auto import tqdm
elif frontend == "console":
from tqdm import tqdm
elif frontend == "gui":
from tqdm.gui import tqdm
elif frontend == "notebook":
from tqdm.notebook import tqdm
else:
raise ValueError(
f"Frontend argument {frontend!r} not supported. "
"Please select one of the following: "
", ".join(["auto", "console", "gui", "notebook"])
)
self.custom_description = False
if "desc" in kwargs.keys():
self.custom_description = True
self.tqdm = tqdm
self.tqdm_kwargs = {"bar_format": "{bar} {percentage:3.0f}% | {desc} "}
self.tqdm_kwargs.update(kwargs)