Download an image from a webpage
# Save the file
img = urllib2.urlopen(imgurl)
localFile = open('desktop.jpg', 'wb')
localFile.write(img.read())
localFile.close()


For opening file it's recommend to do:

with open('desktop.jpg','wb') as localFile:
     localFile.write(img.read())


Which will make sure the file closes regardless.

Also, urllib.urlretrieve does this for you.