How to extract and increment the hour from text (s

2019-03-07 02:11发布

For example I have this text (Input):

Event Time, Monday:
10:01:02,269 to 10:01:08,702
(Reported by John).

Event Time, Sunday:
20:01:08,931 to 20:01:15,234
(Reported by Peter).

...

Then you want to alter and increase the time (only the time), thus (Output):

Event Time, Monday:
10:01:02,369 to 10:01:09,002 #Change the microseconds and seconds
(Reported by John).

Event Time, Sunday:
20:01:09,131 to 20:01:15,934 #Change the microseconds and seconds
(Reported by Peter).

Once I have the times, I can alter. So the problem is how to get only the times. I was thinking that maybe one way would be to collect the times in a list, like this:

times = ['10:01:02,269', '10:01:08,702', '20:01:08,931', '20:01:15,234']

But how to make that? and then, how to increase it in the list? And finally how to print without changing the text.

1条回答
淡お忘
2楼-- · 2019-03-07 02:32
  1. Use pattern '[0-9:,]' to find all the time data.
  2. times.sort() can increase time in the list
  3. print 'it time %s' % str(times[0]) for instance, could print without changing the text
查看更多
登录 后发表回答