Question
I get this error when running a python script =================== RESTART: C:/Users/Terrie/Desktop/1.py =================== Traceback (most recent call last): File C:/Users/Terrie/Desktop/1.py, line 24, in db_cursor.execute(selectSQL,cycle[0]) File
I get this error when running a python script
=================== RESTART: C:/Users/Terrie/Desktop/1.py =================== Traceback (most recent call last): File "C:/Users/Terrie/Desktop/1.py", line 24, in
this is the python script:
import mysql.connector db_con = mysql.connector.connect( # TODO: change the host,user,passwd as per yours host="localhost", user="root", passwd="Tessylou=12", database="accidents", ) # getting the cursor db_cursor = db_con.cursor()
db_cursor.execute('SELECT vtype FROM vehicle_type WHERE vtype LIKE "%otorcycle%";') cycleList = db_cursor.fetchall() selectSQL = (''' select t.vtype, a.accident_severity from accidents_2016 as a join vehicles_2016 as v on a.accident_index = v.accident_index join vehicle_type as t on v.vehicle_type = t.vcode where t.vtype like %s order by a.accident_severity;''') insertSQL = ('''INSERT INTO accident_medians VALUES (%s, %s);''')
for cycle in cycleList: db_cursor.execute(selectSQL,cycle[0]) accidents = cursor.fetchall() quotient, remainder = divmod(len(accidents),2) if remainder: med_sev = accidents[quotient][1] else: med_sev = (accidents[quotient][1] + accidents[quotient+2][1])/2 print('Finding median for',cycle[0]) cursor.execute(insertSQL,(cycle[0],med_sev)) myConnection.commit() myConnection.close() It seems to be the where t.vtype like %s statement. The %s maybe the problem but I am not sure what else to use.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started