The default path of python urlretrieve downloading file via HTTP

拥有回忆 提交于 2019-12-11 12:37:23

问题


We know that we could use urllib.urlretrieve to download file via HTTP to local file system. For example:

import urllib
urllib.urlretrieve ("http://www.example.com/songs/mp3.mp3", "mp3.mp3")

I wonder where is the default path if we download a file like mp3.mp3? I have read python document.

urllib.urlretrieve(url[, filename[, reporthook[, data]]]) Copy a network object denoted by a URL to a local file, if necessary. If the URL points to a local file, or a valid cached copy of the object exists, the object is not copied. Return a tuple (filename, headers)where filename is the local file name under which the object can be found, and headers is whatever the info() method of the object returned by urlopen() returned (for a remote object, possibly cached). Exceptions are the same as for urlopen(). The second argument, if present, specifies the file location to copy to (if absent, the location will be a tempfile with a generated name). The third argument, if present, is a hook function that will be called once on establishment of the network connection and once after each block read thereafter. The hook will be passed three arguments; a count of blocks transferred so far, a block size in bytes, and the total size of the file. The third argument may be -1 on older FTP servers which do not return a file size in response to a retrieval request.

it doesn't mention what is the default path. I wonder if I always need to use absolute path in the second argument?


回答1:


By default,if you don't give any path, the file will be in your current directory. And if your want to put the file in the specify location,you should always use the relative path instead of absolute path because your codes may run on different os system.



来源:https://stackoverflow.com/questions/37455933/the-default-path-of-python-urlretrieve-downloading-file-via-http

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!