Python Forum

Full Version: Check CSV file for value
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
Start with the csv module. That reads csv files.
CVS module won't load on the raspberry pi,
E: unable to locate package csv
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().
(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/m...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/m...les/_csv.c
That said, it still is almost guaranteed to be bundled with python.