Need script to download file at known address

Radioactive Man rm at rm.rm
Thu Sep 16 22:40:10 EDT 2004


On Fri, 17 Sep 2004 12:08:36 +1000, Andrew Durdin <adurdin at gmail.com>
wrote:

>On Fri, 17 Sep 2004 01:46:42 GMT, Radioactive Man <rm at rm.rm> wrote:
>> Here is the test script I came up with:
>> 
>> import urllib
>> f =  urllib.urlopen("http://www.python.org/pics/pythonHi.gif")
>> g = f.read()
>> file = open("trash.gif", "w")
>> file.write(g)
>> file.close()
>
>You're opening the output file in ascii mode, so newlines characters
>are getting converted to the CR/LF combination. Change the second
>parameter to open() to "wb".

That worked.  Thanks.

Looking back through the documentation, I see that open() is really an
alias for file().  Are there any variants of the "open" commmand that
allow location (drive and directory) of the file to be specified as
well, for example, if I wanted to save the file as
"D:\binaries\trash.gif" instead of the default location?   If that's
not possible, then the alternative might be exectuting commands from
the os module to accomplish the same thing.




More information about the Python-list mailing list