[Tutor] Time script help sought!

jfouhy at paradise.net.nz jfouhy at paradise.net.nz
Tue Jan 11 22:49:40 CET 2005


Quoting "Jacob S." <keridee at jayco.net>:

> > The old mx.datetime module (on which Python's datetime module is based, I
> > presume) had a strptime() function which would basically do the reverse (you
> > specify a format string and it would attempt to parse the date string you give
> > it). Unfortunately, Python's datetime module doesn't have such a function.
> > This is the best way I have found of doing it:
> 
> Fortunately, the time module does.
> 
> time.strptime

Yeah, I know.  I used time.strptime in the function which you didn't quote.  The
point is that a hypothetical datetime.datetime.strptime function would return a
datetime object, whereas time.strptime returns a struct_time, which is much less
useful.  Hence a couple of hoops to jump through to convert a struct_time into a
datetime..

-- 
John.


More information about the Tutor mailing list