From b9507b31beb67c9903073f8ae6f89c9735c5f1d0 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Thu, 18 Feb 2021 03:42:07 +0000 Subject: [PATCH] update README --- README.rst | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 42a336c0..40abaa69 100644 --- a/README.rst +++ b/README.rst @@ -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