The most recent answer: if switching to direct strptime() did not improve the running time, then my suspicion is that there are no problems: you just wrote a program, one of whose main goals in life is to call strptime() many times, and you wrote it well enough - with so few other things that it does - that calls to strptime() quite correctly allow you to dominate at runtime. I think you could consider this a success rather than a failure if you did not find that (a) some Unicode or LANG settings do strptime() additional work, or (b) you call it more often than you need. Try, of course, to call it only once for each parsed date. :-)
The following answer after looking at the example date string: Wait! Stay on the line! Why are you parsing a string instead of just using a format string, for example:
"%d/%b/%Y:%H:%M:%S"
The original response to the cuff . If the month was an integer, you could do something like this:
new_entry['time'] = datetime.datetime( int(parsed_line['year']), int(parsed_line['month']), int(parsed_line['day']), int(parsed_line['hour']), int(parsed_line['minute']), int(parsed_line['second']) )
and don't create a large string to make strptime() split again. I wonder if there is a way to access the logic of the month name directly to do this one text conversion?
Brandon rhodes
source share