If I open a file using urllib2, like so:
remotefile = urllib2.urlopen('http://example.com/somefile.zip')
Is there an easy way to get the file name other then parsing the original URL?
EDIT: changed openfile to urlopen... not sure how that happened.
EDIT2: I ended up using:
filename = url.split('/')[-1].split('#')[0].split('?')[0]
Unless I'm mistaken, this should strip out all potential queries as well.
http://example.com/somefile/
) and no path:http://example.com
Your example will fail on the latter for sure (returning "example.com"). So will @insin's final answer. That's another reason why using urlsplit is good advice. – Eugenol