[Tutor] Open a text file, read and print pattern matching
tee chwee liong
tcl76 at hotmail.com
Sun Jan 9 07:25:53 CET 2011
hi,
i have a sampledata as below. Pls refer to output, if found -1, how to list out all the Lane number? And if there is no -1, print PASS. My code is as below section.
thanks
tcl76
####sampledata############
Platform: PC
Tempt : 25
TAP0 :0
TAP1 :1
+++++++++++++++++++++++++++++++++++++++++++++
Port Chnl Lane EyVt
+++++++++++++++++++++++++++++++++++++++++++++
0 1 1 75
0 1 2 -1
0 1 3 10
0 1 4 -1
0 1 5 12
+++++++++++++++++++++++++++++++++++++++++++++
Time: 20s
############################
####output###################
case1: Found -1
Lane 2 FAIL
Lane 4 FAIL
case2: No -1
All Lanes PASS
##########################
####Code####################
fname = "sampledata.txt"
pattern = "-1"
for search in open(fname):
if pattern in search:
print "FAIL"
else:
print "PASS"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110109/e1ae9313/attachment.html>
More information about the Tutor
mailing list