Python正在读取按日期命名的文件



名为data的目录中将有多个txt文件。但我只想readdate of that day as the name的文件。我该怎么做?。

我的代码:

import time
from requests import get
url = "https://zonefiles.io/a/yourApiKey/update/1/"
def domains_ind_day():
with open('../data/{}.txt'.format(time.strftime('%d-%m-%Y', time.gmtime())), 'wb') as file:
response = get(url)
file.write(response.content)

试试这个:

filename = '../data/' + format(time.strftime('%d-%m-%Y', time.gmtime()) + '.txt'
with open(filename, 'wb') as file:

最新更新