[Tutor] Defining Exceptions
Tom Brauch
tom at advm2.com
Wed Feb 2 15:51:24 CET 2011
All,
I am a python neophyte and not terrible well versed in programming (as will
become obvious shortly)
I have a script which is reading a serial device on a schedule. The device
outputs a header at the beginning of every read. I have a data file which I
am appending and would like to eliminate the header so that I end up with
one master data file. A copy of the serial readout is:
*
>
6CSV Type Reports2 - Display All Data3 - Display New Data4 - Display Last
Data5 - Display All Flow Stats6 - Display New Flow Stats7 - Display All
5-Min Flow8 - Display New 5-Min Flow9 - Display Error Log>
4 - Display CSV DataStation,
1Time,Conc(mg/m3),Qtot(m3),no(V),WS(MPS),no(V),RH(%),no(V),AT(C),E,U,M,I,L,R,N,F,P,D,C,T,02/02/11
08:00, 0.042, 0.701, 0.004, 0.1, 0.002, 7, 0.012,
-18.0,0,0,0,0,0,0,0,0,0,0,0,0,
I am only interested in the information following the T, in the header. I
have tried to use an exception to have the script throw out all data prior
to the T, in the header but I don't know how to define this excecption. My
current script looks as follows:
def cycle(ser,prefix):
inRecovery=False
resp=False
# tm.sleep(30.0)
ser.open()
tm.sleep(2)
ser.write('\n\r\n\r\n\r')
resp=buffer_read(ser)
ser.write('6')
resp=buffer_read(ser)
ser.write('3')
resp=buffer_read(ser)
lines = resp.split('\r\n')
waste=lines.pop()
while True:
try:
lines.remove(waste)
except Exception:
??????
for x,row in enumerate(lines):
lines[x]=row.split(',')
if DEBUG: print lines
f=open(prefix,'a')
csvf = csv.writer(f)
csvf.writerows(lines)
f.close()
ser.close()
How do I define the exception so that I get only the data following the
header?
Thanks!
Tomb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110202/101b2705/attachment.html>
More information about the Tutor
mailing list