Is there anyone that know of a script that will download a file in a url to a location on the mac?
I have a url that contains a mp3, and I want to store that mp3 file in a folder on my mac. If there already is a file there, I want to replace it.
import os
import requests
url = "http://your_file_location_url"
path = "/users/myloginname/Documents/stuff i downloaded"
data = requests.get(url).content
if os.path.exists (path):
with open(path + "/filename.txt", 'w') as file_:
file_.write (data)
file_.close()
with open(newfile, 'w') as outfile, open(oldfile, 'r', encoding='utf-8') as infile:
jay (support) wrote:FYI, the close() call is unnecessary
jay (support) wrote:(and I think as written it may actually throw an exception) since you opened it inside a with block
jay (support) wrote:Fun fact which I didn't know until recently, you can actually open multiple files in the same with statement
Users browsing this forum: No registered users and 1 guest