我想用日期归档我的文件,但我有 02 个问题:
from datetime import date, datetime, timedelta
def perdelta(start, end, delta):
curr = start
while curr < end:
yield curr
curr += delta
fo = open("dattes.txt","wb")
for result in perdelta(date(2011, 10, 10), date(2011, 12, 12), timedelta(days=4)):
fo.write(result)
fo.close()
1-我收到此错误:
Traceback(最近一次调用最后一次):文件“C:\test\date.txt”,第 12 行,在 fo.write(result) 类型错误:必须是字符串或缓冲区,而不是 datetime.date
2-我希望输出日期是连续的(在日、月和年之间没有“-”)