Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify the file path in which to download using python

urllib.request.urlretrieve ("http://bogoroditsa.tk/Grant's%20Libraries/", "ExtraFunctionality.py")

How do I specify, using the command above, the file path in which to download the file? Currently, the code above just downloads the file in the same path as the program is being run in. I would like to specify this download path, how do I do so?

like image 275
Ulsting Avatar asked Dec 21 '22 06:12

Ulsting


2 Answers

Instead of just "ExtraFunctionality.py" you can also provide a full path:

urllib.request.urlretrieve ("http://bogoroditsa.tk/Grant's%20Libraries/",
                                             "/home/foo/ExtraFunctionality.py")
like image 127
Ashwini Chaudhary Avatar answered Dec 22 '22 18:12

Ashwini Chaudhary


The second argument is the local filename:

 urllib.urlretrieve ("http://bogoroditsa.tk/Grant's%20Libraries/ExtraFunctionality.py", theLocalFilename)

For details, see the documentation for urllib, under urlretrieve:

The second argument, if present, specifies the file location to copy to (if absent, the location will be a tempfile with a generated name).

like image 41
Reed Copsey Avatar answered Dec 22 '22 19:12

Reed Copsey