You cannot use both statements; the datetime
module contains a datetime
type. The local name datetime
in your own module can only refer to one or the other.
Use only import datetime
, then make sure that you always use datetime.datetime
to refer to the contained type:
import datetime
today_date = datetime.date.today()
date_time = datetime.datetime.strptime(date_time_string, '%Y-%m-%d %H:%M')
Now datetime
is the module, and you refer to the contained types via that.
Alternatively, import all types you need from the module:
from datetime import date, datetime
today_date = date.today()
date_time = datetime.strptime(date_time_string, '%Y-%m-%d %H:%M')
Here datetime
is the type from the module. date
is another type, from the same module.