Skip to content Skip to sidebar Skip to footer

Retrieve Randomly Preformatted Text From Text File

I am writing a python script to get a string formatted as StartTime='mm/dd/yyyy hh:mm:ss:ccc' and EndTime='mm/dd/yyyy hh:mm:ss:ccc' located in a text file. So I proceed to search

Solution 1:

import re

def getTimeCode(fn):
    with open(fn, 'r') as f:
        for line in f:
            m = re.search(r'(\w)="(\d\d/\d\d/\d\d\d\d \d\d:\d\d:\d\d:\d\d\d)"', line)
            if m:
                if m.group(1) == 'StartTime':
                    # do something with m.group(2)
                elif m.group(1) == 'EndTime':
                    # do something with m.group(2)
                else:
                    # m.group(1) unknown

Post a Comment for "Retrieve Randomly Preformatted Text From Text File"