hannah
hannah

Reputation: 909

python datetime.strptime AttributeError

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'

Upvotes: 1

Views: 1542

Answers (1)

Celada
Celada

Reputation: 22261

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

Upvotes: 3

Related Questions