我正在尝试弄清楚如何检查下载是否已完成。基本上,我希望它等待文件下载完成,然后打印:下载完成。
以下是我的当前代码以及我想要的操作:
from urllib import request
print("Are you sure you want to download the newest file? y/n")
answer = input()
while True:
if answer == 'y':
print("Downloading file...")
downloading = True
request.urlretrieve("FILE_URL", "FILE_NAME")
elif answer == 'n':
exit()
else:
print("That is not a valid answer, please answer with y/n.")
answer = input()
#I need some sort of function here that checks if the file is still being
#downloaded
when downloading == False:
print("Download Completed.")
while answer is not 'y' or 'n':
并不像你想象的那样工作。请参阅如何测试多个变量是否等于一个值?进行了解。我会将这部分内容编辑掉,因为与问题无关。 - Aran-Fey