title: Using urllib2 in Python. How do I get the name of the file I am downloading?
body: <p>I am a python beginner.  I am using urllib2 to download files.  When I download a file, I specify a filename to with which to save the downloaded file on my hard drive.  However, if I download the file using my browser, a default filename is automatically provided.</p>
  
  <p>Here is a simplified version of my code:</p>
  
  <pre><code>def downloadmp3(url):
      webFile = urllib2.urlopen(url)
      filename = 'temp.zip'
      localFile = open(filename, 'w')
      localFile.write(webFile.read())
  </code></pre>
  
  <p>The file downloads just fine, but if I type the string stored in the variable "url" into my browser, there is a default filename given to the file when I download it.  I want to use this filename for my downloaded file not 'temp.zip' or whatever I assign it.</p>
  
  <p>How do I use urllib2 (or some other Python library) to save the file with the filename that the server I am downloading from intends it to have?</p>
  
  <p>If anyone doesn't understand this question, please say so, so that I can try to make it clearer.</p>