Aug-21-2020, 10:32 AM
I came across the following code in a website.
import requests file_url = "http://codex.cs.yale.edu/avi/db-book/db4/slide-dir/ch1-2.pdf" r = requests.get(file_url, stream = True) with open("python.pdf","wb") as pdf: for chunk in r.iter_content(chunk_size=1024): # writing one chunk at a time to pdf file if chunk: pdf.write(chunk)Now the file is being written in chunks. So why it is opened as "w" (write mode), instead of "a" (append mode) because if we open the file as "w" we know that when the latest chunk will be written it will overwrite the file and we will loose the previous chunks.