i have these lines here
for line in fo.readlines():
linedata.append(line)
vals = linedata[kk].split(',')
print (' val 0=',vals[0])
<b>if vals[0]='CD':</b>
print (' breakers ^^^^^^^^^^')
cntCB1+=1
i get an error on the if line to detect some words
i tried many ways but does not want to work!
how can this work?
thanks
happy 2.5
zeffii
(zeffii)
August 6, 2011, 11:14am
2
if vals[0] == ‘CD’:
comparison, not assignment.
it still does not see the word in this field!
is there some nul values added and should i remove the null values before and after the word may be
and how ?
thanks
zeffii
(zeffii)
August 6, 2011, 11:43am
4
what is KK ? what is the content of linedata[kk]
kk is a line counter in a for loop for the file
here is the print out for this
the value i’m tring to get is this CD which is the first field on a line = val[0]
from console output
val 0= CD
strip command CD vals= CD
b= CD
kk= 10 len= 2
val[0]= CD
############### kk= 10 CB qty = 0
for this field i cannot see it with the if command !
&&&&&&&&&&&&&&&&&
here is the code for the loop
for line in fo.readlines():
linedata.append(line)
vals = linedata[kk].split(',')
print (' val 0=',vals[0])
print (' strip command ' , vals[0].strip(),' vals=',vals[0])
b1=vals[0].rstrip()
print ('b=',b1)
print ('kk=',kk,'len=',len(vals))
print (' val[0]=',vals[0])
<b>if vals[0]=="CD":</b>
print (' $$$$$$$$$$$$$$$$$$$$$$$ breakers ^^^^^^^^^^')
cntCB1+=1
print ('############### kk=',kk, 'CB qty =',cntCB1)
if kk>12:
break
print ()
kk+=1
very strange i tried to remove null values before and after and it does not work
tried with single quote or double quote and same thing
thanks
zeffii
(zeffii)
August 6, 2011, 1:29pm
6
correct your indentation. your if statement vals[0] is outside the fo.readlines(): for loop.
no not that i use Tab and eveything is aligned as it should be or i would get indentation error !!
tried this one
val 0= CD1
strip command CD1 vals= CD1
b= CD1
kk= 10 len= 2
val[0]= CD1
different then CD1
############### kk= 10 CB qty = 0
and get this on console
val 0= CD1
strip command CD1 vals= CD1
b= CD1
kk= 10 len= 2
val[0]= CD1
different then CD1
############### kk= 10 CB qty = 0
so i can print the value CD1 it has a lenght of 2 upper case
but the if equal does not recognise it !
don’t know what is doing this to miss this value
i’ll wait tomorrow may be i’'ll find it tomorrow morning!
but the if command does see a difference but which one !
thanks
happy 2.5
found it there was nulls values on this field
now it works with this
b1=vals[0].rstrip()
print (‘b1=’,b1)
print (‘kk=’,kk,‘len=’,len(vals[0]))
print(‘len b1=’,len(b1))
print (’ val[0]=’,vals[0])
if b1==“CD1”:
print (’ ***************************** breakers ^^^^^^^^^^’)
cntCB1+=1
which is cool!
thanks anyway
zeffii
(zeffii)
August 6, 2011, 2:35pm
9
show me the file you want to parse.