mirror of https://github.com/tqdm/tqdm.git
261 lines
5.3 KiB
Plaintext
261 lines
5.3 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"This file is part of the [test suite](./tests) and will be moved there when [nbval#116](https://github.com/computationalmodelling/nbval/issues/116#issuecomment-793148404) is fixed.\n",
|
|
"\n",
|
|
"See [DEMO.ipynb](DEMO.ipynb) instead for notebook examples."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from functools import partial\n",
|
|
"from time import sleep\n",
|
|
"\n",
|
|
"from tqdm.notebook import tqdm_notebook\n",
|
|
"from tqdm.notebook import tnrange\n",
|
|
"\n",
|
|
"# avoid displaying widgets by default (pollutes output cells)\n",
|
|
"tqdm = partial(tqdm_notebook, display=False)\n",
|
|
"trange = partial(tnrange, display=False)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Help on function display in module tqdm.notebook:\n",
|
|
"\n",
|
|
"display(self, msg=None, pos=None, close=False, bar_style=None)\n",
|
|
" Use `self.sp` to display `msg` in the specified `pos`.\n",
|
|
" \n",
|
|
" Consider overloading this function when inheriting to use e.g.:\n",
|
|
" `self.some_frontend(**self.format_dict)` instead of `self.sp`.\n",
|
|
" \n",
|
|
" Parameters\n",
|
|
" ----------\n",
|
|
" msg : str, optional. What to display (default: `repr(self)`).\n",
|
|
" pos : int, optional. Position to `moveto`\n",
|
|
" (default: `abs(self.pos)`).\n",
|
|
"\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"help(tqdm_notebook.display)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# basic use"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"application/vnd.jupyter.widget-view+json": {
|
|
"model_id": "7c18c038bf964b55941e228503292506",
|
|
"version_major": 2,
|
|
"version_minor": 0
|
|
},
|
|
"text/plain": [
|
|
" 0%| | 0/10 [00:00<?, ?it/s]"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"0\n",
|
|
"1\n",
|
|
"2\n",
|
|
"3\n",
|
|
"4\n",
|
|
"5\n",
|
|
"6\n",
|
|
"7\n",
|
|
"8\n",
|
|
"9\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"for i in tqdm_notebook(range(10)):\n",
|
|
" sleep(0.01)\n",
|
|
" print(i)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# repr"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
" 0%| | 0/9 [00:00<?, ?it/s]\n",
|
|
" 0%| | 0/9 [00:00<?, ?it/s]\n",
|
|
"1\n",
|
|
" 0%| | 0/9 [00:00<?, ?it/s]\n",
|
|
" 0%| | 0/9 [00:00<?, ?it/s]\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"with trange(1, 10) as pbar:\n",
|
|
" print(pbar)\n",
|
|
" print(pbar.container)\n",
|
|
" it = iter(pbar)\n",
|
|
" print(next(it))\n",
|
|
" print(pbar)\n",
|
|
" print(pbar.container)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# display"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"t = trange(10)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
" 0%| | 0/10 [00:00<?, ?it/s]\n",
|
|
" 0%| | 0/10 [00:00<?, ?it/s]\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(t)\n",
|
|
"print(t.container)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 7,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"for i in t:\n",
|
|
" pass"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 8,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"100%|██████████| 10/10 [00:00<00:00, 169.05it/s]\n",
|
|
"100%|##########| 10/10 [00:00<00:00, 168.12it/s]\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(t)\n",
|
|
"print(t.container)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# no total"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 9,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"no total: 0it [00:00, ?it/s]\n",
|
|
"no total: 1it [00:00, 33.56it/s]\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"with tqdm(desc=\"no total\") as t:\n",
|
|
" print(t)\n",
|
|
" t.update()\n",
|
|
" print(t)"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python [conda env:tqdm]",
|
|
"language": "python",
|
|
"name": "conda-env-tqdm-py"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython"
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|