I'm trying to make a code that downloads a file if it doesn't exist
import requests
from os.path import exists
def downloadfile(url):
if exists('file.txt')==False:
local_filename = url.split('/')[-1]
with requests.get(url, stream=True) as r:
r.raise_for_status()
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
f.write(chunk)
return
downloadfile('https://url.to/file.txt')
my folder:
testfolder
test.py
file.txt
...
in idle
from os.path import exists
exists('file.txt') # True
in test.py, exists() say False how fix it?