I have the following working code:
import datetime
d = "2012-12-19"
f = map(int, d.split('-') )
day = datetime.date( f[0], f[1], f[2] )
print day
but when I try to write it this way:
day = datetime.date( f )
I get an exception: TypeError: an integer is required
Why is that and how could I write this better?
Best is to use the
datetime.strptime()method:Demo:
You are not passing
f[0], etc. in though, your method would have worked had you done that or: