Python: The opposite of `datetime.date.isocalendar()`

This question already has an answer here:

  • What's the best way to find the inverse of datetime.isocalendar()? 7 answers

  • EDIT Found question with solution: What's the best way to find the inverse of datetime.isocalendar()?

    My solution had mistakes. On googling saw previous question which upon testing below worked. (See top answered question in above link for definition of iso_to_gregorian ). (Basically find iso year start date and then use timedelta to find current date from day and week number.

    for i in range(-10000,10000,1):
        x = datetime.datetime.today().date() + datetime.timedelta(i)
        x_iso = datetime.datetime.isocalendar(x)
        assert iso_to_gregorian(*x_iso) == x
    
    链接地址: http://www.djcxy.com/p/51194.html

    上一篇: 文件重命名问题?

    下一篇: Python:与datetime.date.isocalendar()相反