sync readme with DEMO.ipynb

This commit is contained in:
Casper da Costa-Luis 2020-05-03 00:04:23 +01:00
parent e00501a591
commit f0bdabd2fa
No known key found for this signature in database
GPG Key ID: 986B408043AE090D
1 changed files with 36 additions and 3 deletions

View File

@ -431,8 +431,6 @@
"\n",
" Extra CLI Options\n",
" -----------------\n",
" name : type, optional\n",
" TODO: find out why this is needed.\n",
" delim : chr, optional\n",
" Delimiting character [default: '\\n']. Use '\\0' for null.\n",
" N.B.: on Windows systems, Python converts '\\n' to '\\r\\n'.\n",
@ -444,6 +442,8 @@
" `unit_scale` to True, `unit_divisor` to 1024, and `unit` to 'B'.\n",
" manpath : str, optional\n",
" Directory in which to install tqdm man pages.\n",
" comppath : str, optional\n",
" Directory in which to place tqdm completion.\n",
" log : str, optional\n",
" CRITICAL|FATAL|ERROR|WARN(ING)|[default: 'INFO']|DEBUG|NOTSET.\n",
"\n"
@ -706,7 +706,7 @@
" self.update(b * bsize - self.n) # will also set self.n = b * bsize\n",
"\n",
"eg_link = \"https://caspersci.uk.to/matryoshka.zip\"\n",
"with TqdmUpTo(unit='B', unit_scale=True, miniters=1,\n",
"with TqdmUpTo(unit='B', unit_scale=True, unit_divisor=1024, miniters=1,\n",
" desc=eg_link.split('/')[-1]) as t: # all optional kwargs\n",
" urllib.urlretrieve(eg_link, filename=os.devnull,\n",
" reporthook=t.update_to, data=None)\n",
@ -774,6 +774,39 @@
" fout.write(chunk)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `requests` equivalent is nearly identical, albeit with a `total`:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"matryoshka.zip: 254kB [00:00, 460kB/s] \n"
]
}
],
"source": [
"import requests, os\n",
"from tqdm import tqdm\n",
"\n",
"eg_link = \"https://caspersci.uk.to/matryoshka.zip\"\n",
"response = requests.get(eg_link, stream=True)\n",
"with tqdm.wrapattr(open(os.devnull, \"wb\"), \"write\",\n",
" miniters=1, desc=eg_link.split('/')[-1],\n",
" total=response.headers.get('content-length')) as fout:\n",
" for chunk in response.iter_content(chunk_size=4096):\n",
" fout.write(chunk)"
]
},
{
"cell_type": "markdown",
"metadata": {},