Search code examples
pythoniteratorurllibclint

Using the clint progress bar to show the status of urllib.urlretrieve()


The clint progress bar is based on an iterator.
urllib.urlretrieve() has a callback that reports the completion of a chunk downloading.
Can I set the iterator to be in a certain position everytime the callback is called?


Solution

  • Looking at the source, i see that it only goes up. To start at a specific value, use:

    for i in progress.dots(range(your_start_value)): pass
    

    To backspace, try:

    sys.stderr.write(' \b\b' * amount); sys.stderr.flush()
    

    That probably won't work without using the colorama module's locate feature, in which case you'd be better off simply writing ("=" * percent_done + " " * percent_left).