22

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'

2 Answers 2

27

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.

Sign up to request clarification or add additional context in comments.

1 Comment

@Gunther, you method works for python3, could you explain a little bit?
14

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"))

1 Comment

Thanks. This worked while the accepted answer didn't.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.