TypeError: 'datetime.datetime' object is not callable

后端 未结 2 927
清歌不尽
清歌不尽 2021-02-14 09:08

I have some Python code that iterates through all the days between two start dates. The start date is always November 1st and the end date is always May 31st. However, the code

2条回答
  •  天涯浪人
    2021-02-14 09:29

    I think that the following line:

    date = datetime(year=time2, month=time3, day=time4)
    

    is the issue. Here, you are re-defining date to have a different value (that can't be called) to the date class (which could be).

    On the 'second pass through', it gets to:

    d1 = date(x,11,01)
    

    and date isn't what it used to be (it can't be called), and so you get the error.

    Maybe change variable name to be something else, e.g. dte?

提交回复
热议问题