[Tutor] Help: wget-- how does it work?

Kent Johnson kent37 at tds.net
Sun May 29 05:00:01 CEST 2005

Aaron Elbaz wrote:
> One of my favourite unix applications is wget.
> Thinking how easy (and fun) it might be to implement with pythons
> excellent librairies has led me to a few questions.
> First, I found the progress bar class from aspn
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/168639
> This could be used to simulate wgets progress bar. What I'm trying to
> figure out now is how one would stat a file as it was being downloaded
> so that I can feed information to the progress bar, and what the most
> optimal way to do this is?

See urllib.urlretrieve(). The reporthook argument gives you all the information you need to create a 
progress indicator.

Here is Guido van Rossum's own Python wget, from the Python Cookbook:

import sys, urllib
def reporthook(*a): print a
for url in sys.argv[1:]:
     i = url.rfind('/')
     file = url[i+1:]
     print url, "->", file
     urllib.urlretrieve(url, file, reporthook)


More information about the Tutor mailing list