[Tutor] please help: conditional statement and printing element
Kent Johnson
kent37 at tds.net
Tue Jan 11 21:13:29 CET 2005
kumar s wrote:
> Dear group,
> For some reason my brain cannot think of any other
> option than what I have in my script. Could any one
> please help me in suggesting.
>
> What I have : (File name : psl)
> 22 2 457:411 25 0
> 25 0 457:411 25 0
> 25 0 457:411 25 0
> 25 0 457:411 25 0
> 25 0 457:411 25 0
> 25 0 457:411 25 0
> 25 0 457:411 25 0
> 25 0 457:411 25 0
> 25 0 457:411 25 0
> 22 0 457:411 25 0
> 25 0 457:411 25 0
> 25 0 457:411 25 0
> 24 1 457:411 25 0
> 22 0 457:411 25 0
> 21 0 457:411 25 0
> 25 0 457:411 25 0
> 25 0 457:411 25 0
>
>
> What to do:
> I want to print values that are 25 in column 1 and not
> the other values such as 24,22,21 etc.
>
>
> My script:
>
>>>>for i in range(len(psl)):
>
> col = split(psl[i],'\t')
> col1 = col[0]
col1 is a text string, not a number, e.g. '25', not 25. The simplest thing is just to compare it to
'25':
> if col1 == 25:
if col1 == '25':
Kent
> print col[0]+'\t'+col[1]+'\t'+col[17]
>
>
>
>
> Result: I get nothing. Am I doing something very
> wrong. Why isnt if col1 == 25: functional.
>
> My idea is to check if col[0] == 25: then print
> columns 1,18 etc.
>
> Can you please help me.
>
> Thanks
> K
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list