datetime.time() class - How to pass it a time string?

Miles semanticist at
Tue Jul 24 19:37:20 CEST 2007

On 7/24/07, Robert Dailey wrote:
> Hi,
> I have a string in the following format:
> "00:00:25.886411"
> I would like to pass this string into the datetime.time() class and
> have it parse the string and use the values. However, the __init__()
> method only takes integers (which means I'd be forced to parse the
> string myself). Does anyone know of a way I can make it use the
> string? Thanks.

timestr = "00:00:25.886411"
timesep = re.compile('[:.]')
datetime.time(*[int(i) for i in timesep.split(timestr)])

More information about the Python-list mailing list