I am trying to grab values from a log file using Python's regular expression and in that process I have a few if
statements. The section of the code which grabs the values is as follows:
# Opening the log file for reading
with open(logFile, 'r') as logfile_read:
for line in logfile_read:
line = line.rstrip()
# To extract Time or iteration
if 'Time' in line:
iteration_time = re.findall(r'^Time\s+=\s+(.*)', line)
# To extract local, global and cumulative values
if 'local' in line:
local_global_cumu = re.search(r'sum\s+local\s+=\s+(.*),\s+global\s+=\s+(.*),\s+cumulative\s+=\s+(.*)', line)
if local_global_cumu:
contLocal_0_value = local_global_cumu.group(1)
contGlobal_0_value = local_global_cumu.group(2)
contCumulative_0_value = local_global_cumu.group(3)
for t in iteration_time:
contLocal.write("%s\t%s\n" %(t, contLocal_0_value))
contGlobal.write("%s\t%s\n" %(t, contGlobal_0_value))
contCumulative.write("%s\t%s\n" %(t, contCumulative_0_value))
# To extract execution and cpu time
if 'ExecutionTime' in line:
execution_cpu_time = re.search(r'^ExecutionTime\s+=\s+(.*)\s+s\s+ClockTime\s+=\s+(.*)\s+s', line)
if execution_cpu_time:
execution_time_0_value = execution_cpu_time.group(1)
cpu_time_0_value = execution_cpu_time.group(2)
for t in iteration_time:
print t
In the second if
statement, I am able to get values of t
. However, in the subsequent if
statement, when I try to print t
, nothing comes. I am not sure where I have gone wrong.