Изменение места загрузкиPython

Программы на Python
Anonymous
Изменение места загрузки

Сообщение Anonymous »

У меня есть скрипт, который загружает файл в папку. Сценарии работают правильно, но загружаемые сценарии попадают в папку моего проекта. Я хотел бы разместить эти загрузки в другом месте: L:\Data\Scores\ACT
Где я могу включить или изменить это в своем сценарии? Нужно ли мне определять путь или каким-то образом изменить DOWNLOAD_DIR?
Я использую VS Code.
Изображение того, где в данный момент находятся файлы загружено на
import requests
import json
import os
import re
from urllib.parse import urlparse, unquote
from pathlib import Path

# SET THE API URL

URL = "https://api.datalab.nrccua.org/v1"

# SET YOUR API KEY

API_KEY = "xxxxx"

# SET YOUR ORG UID

ORGANIZATION_UID = "xxxxx"

# override this if you want

DOWNLOAD_DIR = os.path.dirname(__file__)
DOWNLOAD_DIR = Path(DOWNLOAD_DIR)

if len(files_to_download) == 0:
print(f"No files to download!")
else:
for file in files_to_download:
parsed_url = urlparse(file)
\# get the file name from the url, unescape it, and then replace whitespace with underscore
escaped_filename = get_valid_filename(unquote(os.path.basename(parsed_url.path)))
download_path = DOWNLOAD_DIR / escaped_filename
print(f"Downloading file from url {file}")
\# don't use the session here
download_file_response = requests.get(file, allow_redirects=True, stream=True)
if download_file_response.ok:
print(f"Writing file to {download_path}.")
with open(download_path, "wb") as f:
\# we are going to chunk the download because we don't know how large the files are
for chunk in download_file_response.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
else:
print(f"There was an error retrieving {file} with status code {download_file_response.status_code}.")
print(f"{download_file_response.content}")


Подробнее здесь: https://stackoverflow.com/questions/783 ... d-location

Вернуться в «Python»