Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #65424
| Date | 2014-02-04 14:05 +0000 |
|---|---|
| From | MRAB <python@mrabarnett.plus.com> |
| Subject | Re: Logging data from Arduino using PySerial |
| References | <e3b195f8-5a17-4536-9926-2b2ab193719c@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.6388.1391522708.18130.python-list@python.org> (permalink) |
On 2014-02-04 04:07, Thomas wrote:
> I've written a script to log data from my Arduino to a csv file. The script works well enough but it's very, very slow. I'm quite new to Python and I just wanted to put this out there to see if any Python experts could help optimise my code. Here it is:
>
[snip]
> # Cleaning the data_log and storing it in data.csv
> with open('data.csv','wb') as csvfile:
> for line in data_log:
> line_data = re.findall('\d*\.\d*',line) # Find all digits
> line_data = filter(None,line_data) # Filter out empty strings
> line_data = [float(x) for x in line_data] # Convert Strings to float
>
> for i in range(1,len(line_data)):
> line_data[i]=map(line_data[i],0,1023,0,5)
>
You're doing this for every in line the log:
> csvwrite = csv.writer(csvfile)
[snip]
Try moving before the 'for' loop so it's done only once.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Logging data from Arduino using PySerial Thomas <t.tchorzewski@gmail.com> - 2014-02-03 20:07 -0800
Re: Logging data from Arduino using PySerial Chris Angelico <rosuav@gmail.com> - 2014-02-04 15:47 +1100
Re: Logging data from Arduino using PySerial Thomas <t.tchorzewski@gmail.com> - 2014-02-03 20:57 -0800
Re: Logging data from Arduino using PySerial Chris Angelico <rosuav@gmail.com> - 2014-02-04 16:18 +1100
Re: Logging data from Arduino using PySerial Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-02-04 08:56 -0500
Re: Logging data from Arduino using PySerial MRAB <python@mrabarnett.plus.com> - 2014-02-04 14:05 +0000
csiph-web