Save return of fields in variables in python

0

I made a query in mysql with python and show the result:

cursor = db.cursor()    
cursor.execute("SELECT Dias, HoraConsulta, HoraSaida, nome, Consulta, centrodb.LocalConsulta.Descricao, Contato FROM centrodb.RegistoConsultas LEFT OUTER JOIN centrodb.LocalConsulta ON centrodb.LocalConsulta.Id = centrodb.RegistoConsultas.'Local' LEFT OUTER JOIN centrodb.utentes ON centrodb.utentes.codigoutente = centrodb.RegistoConsultas.Utente LEFT OUTER JOIN centrodb.DiasSemana ON centrodb.DiasSemana.Id = centrodb.RegistoConsultas.DiaSemana")    
myresult = cursor.fetchone()    
print(myresult)

Instead of print, I want to store in columns each column returned in the query in python

    
asked by anonymous 06.12.2018 / 17:55

1 answer

1

According to documentation , the fetchone will be a tuple with the values returned from the database. So, to create variables, you can do the deconstruction of the tuple:

dias, hora_consulta, hora_saida, ... = myresult

Thus, each value of the tuple will be stored in its variable.

    
06.12.2018 / 18:21