<p>If I open a file using urllib2, like so:</p>

<pre><code>remotefile = urllib2.urlopen('http://example.com/somefile.zip')
</code></pre>

<p>Is there an easy way to get the file name other then parsing the original URL?</p>

<p>EDIT: changed openfile to urlopen... not sure how that happened.</p>

<p>EDIT2: I ended up using:</p>

<pre><code>filename = url.split('/')[-1].split('#')[0].split('?')[0]
</code></pre>

<p>Unless I'm mistaken, this should strip out all potential queries as well.</p>

Do you mean
```
urllib2.urlopen
```
?  There is no function called
```
openfile
```
in the
```
urllib2
```
module.
Anyway, use the
```
urllib2.urlparse
```
functions:
```
```
>>> from urllib2 import urlparse
>>> print urlparse.urlsplit('http://example.com/somefile.zip')
('http', 'example.com', '/somefile.zip', '', '')
```
```
Voila.