not getting date time from correctly formatted string

I’m using this code to get the time from lines in a file.

    for line in f:
        try:
            dt = parser.parse(line).replace(tzinfo=None)
            print dt
        except Exception, e:
            continue

Nothing is printed out, and line are of the form
"Fri May 15 11:22:54 EDT 2015" (generated by date command). When I do

parser.parse("Fri May 15 11:22:54 EDT 2015").replace(tzinfo=None)

directly, I get the correct result.


Source: python

Leave a Reply