I am looking for a quick way to download a file via HTTP, using a Python one-liner from the command line (similar to the functionality of wget
or curl
). The idea is to enable a quick copy/paste to download distutils
on Windows.
I know of one solution (see my answer below). I'm interested in other solutions that consider the following:
- Concise
- Most "Pythonic" solution
- Compatible with both Python 2 and Python 3
- Cross-platform
- Can deal with large files efficiently
- No dependencies (we're fetching
distutils
here. It's unlikely we'll have access torequests
at this stage) - Correctly handles various HTTP headers, such as
Content-Disposition
c:\python27\python.exe -c "from urllib import urlretrieve; urlretrieve('https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py', 'ez_setup.py')" & c:\python27\python.exe ez_setup.py