[Tutor] Open a text file, read and print pattern matching

tee chwee liong tcl76 at hotmail.com
Sun Jan 9 14:31:30 CET 2011


hi,
 
there is error when running the code:
> Traceback (most recent call last):
> File "C:/Python25/myscript/log/readfile9.py", line 5, in <module>
> port, channel, lane, eyvt = line.split()
> ValueError: need more than 2 values to unpack

the error is due to below line code:
>port, channel, lane, eyvt = line.split()
 
pls advise. 
 
thanks
tcl76
 
> Date: Sun, 9 Jan 2011 17:44:58 +1100
> From: steve at pearwood.info
> To: tutor at python.org
> Subject: Re: [Tutor] Open a text file, read and print pattern matching
> 
> Please excuse the double post, I had a problem with my email program.
> 
> tee chwee liong wrote:
> > 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.
> 
> > ####Code####################
> > fname = "sampledata.txt" 
> > pattern = "-1"
> > for search in open(fname):
> > if pattern in search:
> > print "FAIL"
> > else:
> > print "PASS"
> 
> fname = "sampledata.txt"
> pattern = "-1"
> failed = False
> for line in open(fname):
> port, channel, lane, eyvt = line.split()
> if int(eyvt) == -1:
> failed = True
> print "Lane %s failed." % lane
> if not failed:
> print "All lanes pass."
> 
> 
> -- 
> Steven
> 
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110109/7630881d/attachment.html>


More information about the Tutor mailing list