TypeError: 'datetime.datetime' object is not callable

后端 未结 2 917
清歌不尽
清歌不尽 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:44

    This is because you are having a variable called date that is shadowing imported datetime.date. Use a different variable name.

    Demo:

    >>> from datetime import date, datetime
    >>> date(01,11,01)
    datetime.date(1, 11, 1)
    >>> date = datetime(year=2014, month=1, day=2)
    >>> date(01,11,01)
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: 'datetime.datetime' object is not callable
    

提交回复
热议问题