So verwenden Sie die gleiche Logik ohne die re.Wie verwende ich DateTime ohne RE?
#!/usr/bin/env python
#Import the regular expression
import re
print "The task Begins"
print " The Begin time is at 03:00:00"
#Set the beginning time and name it as starttime
starttime="03:00:00"
print "The End time is at 03:59:59"
#Set the ending time and name it as endtime
endtime="03:59:59"
#Specify the time format
time_re = re.compile(r'(\d+:\d+:\d+)')
#Using the condition
with open("abc.log", "r") as fh:
for line in fh.readlines():
match = time_re.search(line)
if match:
matchDate = match.group(1)
if matchDate >= starttime and matchDate <= endtime:
print match.string.strip()
print "The task is completed"
PS: Verwenden Sie DateTime und Time.
Was genau das Problem mit dem aktuellen Ansatz ist? –
wir schreiben keine Programme für Sie ... Was ist das Problem? Bist du ein Anfänger im Codieren? –
Ja Mann. Ich möchte das Datetime-Format verwenden. Ich habe regelmäßigen Ausdruck verwendet. Ich bin ein frischerer Mann. Helfen Sie mir. –