Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python dateutil: AttributeError: module 'dateutil' has no attribute 'parse'

Trying to use dateutil to parse dates from an unknown format but none of the documented methods are found?

CODE:

import dateutil
print(dateutil.parser.parse("24.05.2017"))
exit(1)

ERROR:

Traceback (most recent call last):
  File "test.py", line 2, in <module>
    print(dateutil.parser.parse("24.05.2017"))
AttributeError: module 'dateutil' has no attribute 'parser'
like image 423
Corbin Avatar asked Feb 05 '18 21:02

Corbin


2 Answers

As an alternative to the accepted answer, the dotted notation is still valid if you change the import:

import dateutil.parser
print(dateutil.parser.parse("24.05.2017"))
like image 119
tedder42 Avatar answered Nov 04 '22 19:11

tedder42


You can fix this error by modifying your code slightly:

from dateutil import parser
print(parser.parse("24.05.2017"))

This change is needed because of how the dateutil package internally organizes it's modules.

like image 15
Gunther Avatar answered Nov 04 '22 20:11

Gunther