使用python以指定的路径下载文件?

使用python以指定的路径下载文件?,python,python-3.x,python-requests,Python,Python 3.x,Python Requests,您好,我想用python下载一个文件,它工作得很好,但是如何将文件保存在指定的路径中? 我的代码: 你做得完全正确,代码中没有什么需要改进的!要更改其保存到的路径,只需将其放在opne调用的第一个参数中 您只需使用“with”即可,一旦操作完成,它将关闭文件 with open("msgbox.vbs", "wb") as f: f.write(r.content) 如我所说 您的代码必须如下所示: url144 = "https://

您好,我想用python下载一个文件,它工作得很好,但是如何将文件保存在指定的路径中? 我的代码:


你做得完全正确,代码中没有什么需要改进的!要更改其保存到的路径,只需将其放在
opne
调用的第一个参数中

您只需使用“with”即可,一旦操作完成,它将关闭文件

with open("msgbox.vbs", "wb") as f:
    f.write(r.content)
如我所说

您的代码必须如下所示:

url144 = "https://cdn.discordapp.com/attachments/815696193354203157/817144742693437490/msgbox.vbs"
r = requests.get(url144, allow_redirects=True)

open("/path/where/you/want/your/file/msgbox.vbs", "wb").write(r.content)

简单地说,您不需要将
“msgbox.vbs”
放在打开的
“/path/where/you/want/your/file/msgbox.vbs”
,例如
打开(“C:/users/temal/documents/msgbox.vbs”,“wb”)
路径在哪里?
url144 = "https://cdn.discordapp.com/attachments/815696193354203157/817144742693437490/msgbox.vbs"
r = requests.get(url144, allow_redirects=True)

open("/path/where/you/want/your/file/msgbox.vbs", "wb").write(r.content)