py-serial + CSV

Michael Hoffman at mh391.invalid
Tue Aug 23 15:11:59 CEST 2005

McBooCzech wrote:
> So do I have to save to the file first and analyze later on?

Certainly not.

> Or there is an  other way how to process it (read from the serial and
> analyze data) on the fly?

I've never used py-serial, so I was hoping someone else would jump in 
with the best way to do this (or perhaps you can find it in the 
documentation). One way would be to use the iter() built-in to make it 
into an iterable, like this:

iterable = iter(s.readline, "")

Note that you do not call s.readline() here; you are only supplying the 
bound method itself as an argument. iter() will call it later. I'm 
assuming that s.readline returns an empty string when there is no more 
input. Please replace that with whatever end sentinel it actually uses. 

Another way would be to use s.readlines(), which returns a list, which 
is iterable, but you would have to wait until the entire list were 
collected before beginning processing.
Michael Hoffman

More information about the Python-list mailing list