On Jul 27, 4:38 pm, erikcw <erikwickst...@gmail.com> wrote: > I'm trying to figure out how to download just the first few lines of a > large (50mb) text file form a server to save bandwidth. Can Python do > this? > > Something like the Python equivalent of curlhttp://url.com/file.xml| > head -c 2048
urllib.urlopen gives you a file-like object, which you can then read line by line or in fixed-size chunks. For example: import urllib chunk = urllib.urlopen('http://url.com/file.xml').read(2048) At that point, chunk is just bytes, which you can write to a local file, print, or whatever it is you want. John -- http://mail.python.org/mailman/listinfo/python-list