Answer the question
In order to leave comments, you need to log in
How to delete file in python that is downloaded?
import requests
import uuid
import os
unique_filename = str(uuid.uuid1())
path = 'tmp_user/' + unique_filename + '.jpg'
def gen():
url = "https://thispersondoesnotexist.com/image"
response = requests.get(url)
if response.status_code == 200:
with open(path, 'wb') as f:
f.write(response.content)
input()
os.delete(path)
Answer the question
In order to leave comments, you need to log in
Throw input and os.delete into the gen function.
And don't forget to call her.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question