Question: This is suppose to be done inPython Problem 2 - Parse string for datetime Write a program to read through the text file mbox-short.txt. Examine

Problem 2 - Parse string for datetime Write a program to readThis is suppose to be done inPython

Problem 2 - Parse string for datetime Write a program to read through the text file mbox-short.txt. Examine each line in the file in a loop. For the lines that start with "Date:", get the date and time part of the string, use datetime.strptime() to convert it to a datetime object and print out the result. Note that the datetime has 2 types of formats 1. Sat, 05 Jan 2008 09:14:16 2. 2008-01-05 09:12:07 Your code needs to check which type the date is and use appropriate format string to perform the conversion. Be careful that space are not at the beginning or end of the string so the conversion can be successful. Keep a counter to know how many dates are in this log. Print out the counter. Below is an example of first 5 lines of the output. And the total number of dates 54. 2008-01-05 09:12:18 2008-01-05 09:12:07 2008-01-04 18:08:57 2008-01-04 18:08:50 2008-01-04 16:09:02 ... 54

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!