Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why does python 3 give me a syntax error in the data list for csv writer?

I’m running python 3.9.2 on a Raspberry Pi and trying to capture data on a bus and write it to a CSV file. The code used to work on earlier versions of python but now it throws up a syntax error on my data list. Here’s the code …

from subprocess import check_output
import csv
from datetime import datetime
import threading

bai = ['/usr/bin/ebusctl', 'read', '-c', 'bai', '-f']
f39 = ['/usr/bin/ebusctl', 'read', '-c', 'f39', '-f']
header = ['Date','Time','Flow','Return','Room Temp']

with open('/media/pi/VAILLANT/vaillant_log.csv', 'w', newline = '') as f:
    writer = csv.writer(f)
    writer.writerow(header)

def read_ebus():
    threading.Timer(10.0, read_ebus).start()

    date = datetime.today().strftime('%Y-%m-%d')
    time = datetime.today().strftime('%H:%M:%S')
    flow_temp =  float(check_output(bai+['FlowTemp', 'temp']))
    return_temp =  float(check_output(bai+['ReturnTemp', 'temp']))
    room_temp =  float(check_output(f39+['RoomTemp'])

    data = [date,time,flow_temp,return_temp,room_temp]

    with open('/media/pi/VAILLANT/vaillant_log.csv', 'a', newline='') as f:
        writer = csv.writer(f)
        writer.writerow(data)
read_ebus()

… and here’s the error:

 data = [date,time,flow_temp,return_temp,room_temp]
 ^
SyntaxError: invalid syntax

Has the syntax changed for python 3?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Mike

>Solution :

There is a missing closing parenthesis.

Change this line
room_temp = float(check_output(f39+['RoomTemp'])

to
room_temp = float(check_output(f39+['RoomTemp']))

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading