Python Forum
Check CSV file for value - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Check CSV file for value (/thread-5331.html)



Check CSV file for value - Brian1210 - Sep-29-2017

I'm new to python, I'm trying to set up raspberry pi for temp sensor. I got it writing values to CSV file. But now I want to check the Value and if over 67 degrees, send out an email.
I know crontab might be the way I should do it but my main question is what code do I need to check value in CSV file
path is /home/pi/projects/temp/sensors/latest values

I know people what to know what I have but just started learning python and I really have no idea where to start on that. I can not find stuff doing a internet search or a search in the forums

Thank you
Brian


RE: Check CSV file for value - ichabod801 - Sep-29-2017

Start with the csv module. That reads csv files.


RE: Check CSV file for value - Larz60+ - Sep-29-2017

This is a good tutorial: https://www.blog.pythonlibrary.org/2014/02/26/python-101-reading-and-writing-csv-files/


RE: Check CSV file for value - Brian1210 - Sep-29-2017

CVS module won't load on the raspberry pi,
E: unable to locate package csv


RE: Check CSV file for value - ichabod801 - Sep-29-2017

A poor man's csv:

with open(path_to_file) as csv_file:
    for line in csv_file:
        data = line.strip().split(',')
That will parse a basic csv file. It will have problems with quoted strings containing commas. Also, data will be a list of strings. You will need to convert the temperature to a number with int() or float().


RE: Check CSV file for value - nilamo - Sep-29-2017

(Sep-29-2017, 02:47 AM)Brian1210 Wrote: CVS module won't load on the raspberry pi,
E: unable to locate package csv

csv is a pure-python module that's part of python's standard lib: https://github.com/python/cpython/blob/master/Lib/csv.py

If python is installed, and is at least version 2.3, then you have csv.

What's more likely is that you misspelt it, as you did in the very post that I quoted.

*edit: my mistake, the python module adds a few things on top of a c-api: https://github.com/python/cpython/blob/master/Modules/_csv.c
That said, it still is almost guaranteed to be bundled with python.