Hi,
I have a problem with printing.
If I place a print statement after the forth 'IF' statement I have an error (see below)
If I place a print statement after the third 'IF' statement - no errors
Here is the error:
print ("All Lines -->> ", str_t, endt_p, rnt_p, prg_np, '\n')
NameError: name 'str_t' is not defined
Here is the code:
I have a problem with printing.
If I place a print statement after the forth 'IF' statement I have an error (see below)
If I place a print statement after the third 'IF' statement - no errors
Here is the error:
print ("All Lines -->> ", str_t, endt_p, rnt_p, prg_np, '\n')
NameError: name 'str_t' is not defined
Here is the code:
Python:
import os
import re
runtime_l = '," Run Time'
start_tm = '," Start Time'
end_tm = '," End Time'
program_n = '," Test Program Name:'
ftow = open('C:\\01\\sorted_OUT.txt','w')
with open('C:\\02\\en15\\TST2\\1.txt','r') as ftor:
for ln in ftor:
#print (ln)
ln = ln.rstrip()
if start_tm in ln:
*extraWords,st_t1 = ln.split('Time') # Grtting Start Time line #
st_t1=st_t1.replace('"','')
str_t = st_t1
#print ("Start Time Line -->> " , str_t)
if end_tm in ln:
#print (ln)
*extraWords,endt1 = ln.split('Time') # Grtting END Time line #
endt1=endt1.replace('"','')
endt_p = endt1
#print ("ENd Time line -->> " , endt1)
if runtime_l in ln:
#print (ln)
*extraWords,rnt_1 = ln.split('Time') # Grtting Run Time line #
rnt_1=rnt_1.replace('"','')
rnt_p = rnt_1
#print ("Run Time line -->> " , rnt_1)
print ("All Lines -->> ", str_t, endt1, rnt_1, '\n') # NO errors if enabled Print here #
if program_n in ln :
*extraWords,prg_n = ln.split('Name') # Grtting program name line #
prg_n=prg_n.replace('"','')
prg_np = prg_n
print ("Program Name -->> " ,prg_np)
print ("All Lines -->> ", str_t, endt_p, rnt_p, prg_np, '\n') # Produces an error#
ftow.close()