update README

This commit is contained in:
Casper da Costa-Luis 2021-02-18 03:42:07 +00:00
parent 3dc5c1506d
commit b9507b31be
No known key found for this signature in database
GPG Key ID: 986B408043AE090D
1 changed files with 6 additions and 3 deletions

View File

@ -875,6 +875,7 @@ Here's an example with ``urllib``:
import urllib, os
from tqdm import tqdm
urllib = getattr(urllib, 'request', urllib)
class TqdmUpTo(tqdm):
"""Provides `update_to(n)` which uses `tqdm.update(delta_n)`."""
@ -936,12 +937,14 @@ down to:
from tqdm import tqdm
eg_link = "https://caspersci.uk.to/matryoshka.zip"
response = getattr(urllib, 'request', urllib).urlopen(eg_link)
with tqdm.wrapattr(open(os.devnull, "wb"), "write",
miniters=1, desc=eg_link.split('/')[-1]) as fout:
for chunk in urllib.urlopen(eg_link):
miniters=1, desc=eg_link.split('/')[-1],
total=getattr(response, 'length', None)) as fout:
for chunk in response:
fout.write(chunk)
The ``requests`` equivalent is nearly identical, albeit with a ``total``:
The ``requests`` equivalent is nearly identical:
.. code:: python