1
import datetime

print datetime.strptime("00", "%y").year

I would like to be able to pass "00" into datetime.strptime and receive "2000" as an output. However, When I run code, I keep getting this error: AttributeError: 'module' object has no attribute 'strptime'

1 Answer 1

3

strptime is not found directly at the level of the datetime module. It is a classmethod of the datetime type inside the datetime module, so:

print datetime.datetime.strptime("00", "%y").year
Sign up to request clarification or add additional context in comments.

1 Comment

Even after using python for years, a class named datetime inside a module named datetime still makes me scratch my head sometimes

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.