im new to python and Im trying to define a function in python that calls a stored procedure in python using mysql.connector and write the result into a csv file. i have defined a function to call the stored procedure and print the result. But couldn't figure out how to write my result into a csv file instead of printing. Tried some methods found in web but didn't take me anywhere
so far my codes are:
def call_accessionsByaffliction():
try:
conn = mysql.connector.connect( host="localhost", user="root",
password="1232580", database="db")
cur = conn.cursor()
cur.callproc('AccessionsBycauseOfAffliction_year')
for result in cur.stored_results():
print(result.fetchall())
except Error as e:
print(e)
finally:
cur.close()
conn.close()
and
if __name__ == '__main__':
call_accessionsByaffliction()
Any help? Much appreciated