time - Check if line is a timestamp in Python -


i have script runs every 30 minutes on server, , when it's done writes timestamp last line of file. 20+ files in 1 directory. i'm trying write python script check last line of each file , return either "in progress" or "finished at:" message each file depending on if timestamp present or not.

how python determine if string timestamp or not? formatted hh:mm:ss, no month/date indications.

you try match regular expression:

import re if re.match('\d{2}:\d{2}:\d{2}', line): 

would work if line starts 3 2-digit pairs colons in between; depending on else might find in line enough.

another option try , parse it:

import time  try:     time.strptime(line[:8], '%h:%m:%s') except valueerror:     print('not timestamp') else:     print('found timestamp') 

this lot stricter; valueerror thrown whenever line not start timestamp can represent valid time value, hour must in range 0-23, minutes in range 0-59 , seconds in range 0-60.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -