tags:

views:

358

answers:

3

What's the most efficient way of fetching a file from a URL using Python?

+6  A: 

Asked before. Here

Ólafur Waage
+1  A: 
import urllib

def fetchUrl(url):
    res = urllib.urlopen(url)
    page = res.read()
    res.close()
    return page
JacquesB
A: 

Check module urllib2.
If you want to fetch a file via http, you can in simplest option, just use;

from urllib2 import urlopen
f = urlopen("http://some.server/some/directory/some.file")

Then the f object is a file-like object, i.e. it has a .read method you can use to get your file content.

kender