Search code examples
pythondatetimepython-dateutil

AttributeError: 'datetime.datetime' object has no attribute 'write'


Im trying to convert a str to a date object using the python-dateutil library

from dateutil.parser import *

datetime_object = parse('Fri Feb 14 19:39:51 +0000 2020')
pprint("DATETIME", datetime_object )

However i get the following error:

AttributeError: 'datetime.datetime' object has no attribute 'write'


Solution

  • pprint documentation states that the arguments must have the write method implemented. datetime does not. I expect that your easiest path to a solution is to use any of the available str conversions in datetime, such as the various format specifications.