Skip to content

Commit

Permalink
Showing 3 changed files with 20 additions and 8 deletions.
11 changes: 7 additions & 4 deletions .meta/.readme.rst
Original file line number Diff line number Diff line change
@@ -604,13 +604,16 @@ methods, use ``CallbackIOWrapper``:
t.reset()
# ... continue to use `t` for something else
Alternatively, use the even simpler ``wrapattr`` convenience function:
Alternatively, use the even simpler ``wrapattr`` convenience function,
which would condense both the ``urllib`` and ``CallbackIOWrapper`` examples
down to:

.. code:: python
with tqdm.wrapattr(file_obj, "write", total=data.size) as fobj:
for chunk in data:
fobj.write(chunk)
with tqdm.wrapattr(open(os.devnull, "wb"), "write",
miniters=1, desc=eg_link.split('/')[-1]) as fout:
for chunk in urllib.urlopen(eg_link):
fout.write(chunk)
Pandas Integration
~~~~~~~~~~~~~~~~~~
11 changes: 7 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
@@ -784,13 +784,16 @@ methods, use ``CallbackIOWrapper``:
t.reset()
# ... continue to use `t` for something else
Alternatively, use the even simpler ``wrapattr`` convenience function:
Alternatively, use the even simpler ``wrapattr`` convenience function,
which would condense both the ``urllib`` and ``CallbackIOWrapper`` examples
down to:

.. code:: python
with tqdm.wrapattr(file_obj, "write", total=data.size) as fobj:
for chunk in data:
fobj.write(chunk)
with tqdm.wrapattr(open(os.devnull, "wb"), "write",
miniters=1, desc=eg_link.split('/')[-1]) as fout:
for chunk in urllib.urlopen(eg_link):
fout.write(chunk)
Pandas Integration
~~~~~~~~~~~~~~~~~~
6 changes: 6 additions & 0 deletions examples/tqdm_wget.py
Original file line number Diff line number Diff line change
@@ -95,3 +95,9 @@ def update_to(self, b=1, bsize=1, tsize=None):
desc=eg_file) as t: # all optional kwargs
urllib.urlretrieve(eg_link, filename=eg_out, reporthook=t.update_to,
data=None)

# Even simpler progress by wrapping the output file's `write()`
with tqdm.wrapattr(open(eg_out, "wb"), "write",
miniters=1, desc=eg_file) as fout:
for chunk in urllib.urlopen(eg_link):
fout.write(chunk)

0 comments on commit ef653d8

Please sign in to comment.