def parse_two(): # slower than parse_one filename = Settings().get_timelog_file() for line in open(filename): try: time, entry = line.split(': ', 1) time = parse_datetime(time) except ValueError: continue
def parse_three(): # fastest filename = Settings().get_timelog_file() for line in open(filename): time, sep, entry = line.partition(': ') if not sep: continue try: time = parse_datetime(time) except ValueError: continue
def parse_one(): filename = Settings().get_timelog_file() for line in open(filename): if ': ' not in line: continue time, entry = line.split(': ', 1) try: time = parse_datetime(time) except ValueError: continue
def parse_and_strip(): filename = Settings().get_timelog_file() for line in open(filename): time, sep, entry = line.partition(': ') if not sep: continue try: time = parse_datetime(time) except ValueError: continue entry = entry.strip()
def parse_and_collect(): items = [] filename = Settings().get_timelog_file() for line in open(filename): time, sep, entry = line.partition(': ') if not sep: continue try: time = parse_datetime(time) except ValueError: continue entry = entry.strip() items.append((time, entry)) return items
def parse_and_sort_unicode_piecemeal(): items = [] filename = Settings().get_timelog_file() for line in open(filename, 'rb'): time, sep, entry = line.partition(b': ') if not sep: continue try: time = parse_datetime(time.decode('ASCII')) except (ValueError, UnicodeError): continue entry = entry.strip().decode('UTF-8') items.append((time, entry)) items.sort(key=itemgetter(0)) return items
def parse_and_sort_unicode(): items = [] filename = Settings().get_timelog_file() for line in open(filename, 'rb').read().decode('UTF-8').splitlines(): time, sep, entry = line.partition(': ') if not sep: continue try: time = parse_datetime(time) except ValueError: continue entry = entry.strip() items.append((time, entry)) items.sort(key=itemgetter(0)) return items
def parse_and_sort_incorrectly(): items = [] filename = Settings().get_timelog_file() for line in open(filename): time, sep, entry = line.partition(': ') if not sep: continue try: time = parse_datetime(time) except ValueError: continue entry = entry.strip() items.append((time, entry)) items.sort() # XXX: can reorder lines return items