type object 'datetime.datetime' has no attribute 'datetime'

前端 未结 8 1617
情深已故
情深已故 2020-11-28 03:37

I have gotten the following error:

type object \'datetime.datetime\' has no attribute \'datetime\'

On the following line:

<
8条回答
  •  萌比男神i
    2020-11-28 04:15

    You should really import the module into its own alias.

    import datetime as dt
    my_datetime = dt.datetime(year, month, day)
    

    The above has the following benefits over the other solutions:

    • Calling the variable my_datetime instead of date reduces confusion since there is already a date in the datetime module (datetime.date).
    • The module and the class (both called datetime) do not shadow each other.

提交回复
热议问题