Jun-23-2019, 09:35 PM
I have the fallowing code.
for (ID, Info) in mycursor:
print("ID {}, Population {}".format(ID, Info))
It is returning a table with values like this:
ID 4079, Population {"Population": 92020}
I want it to return:
ID 4079, Population 92020
I am stuck trying to parse this. Not sure how to tackle this. I am new to Python.
Thanks to everyone who read this.
Not sure if this is decent but this is what I came up with on my own.
for (ID, Info) in mycursor:
print("ID {}, Population {}".format(ID, Info))
It is returning a table with values like this:
ID 4079, Population {"Population": 92020}
I want it to return:
ID 4079, Population 92020
I am stuck trying to parse this. Not sure how to tackle this. I am new to Python.
Thanks to everyone who read this.
Not sure if this is decent but this is what I came up with on my own.
import json import mysql.connector mydb = mysql.connector.connect( host="localhost", user="####", passwd="####", database="world_x") mycursor = mydb.cursor() selectIdInfoSQL = "SELECT ID, Info from world_x.city" mycursor.execute(selectIdInfoSQL) for (ID, Info) in mycursor: pop = Info pop = pop[15:len(pop)-1] print("ID {}, Population {}".format(ID, pop)) UpdateSQL = "UPDATE world_x.city set Population = %s WHERE ID = %s" value = (pop, ID) mydb2 = mysql.connector.connect( host="localhost", user="####", passwd="####", database="world_x") mycursor2 = mydb2.cursor() mycursor2.execute(UpdateSQL, value) mydb2.commit() print(mycursor2.rowcount, "record(s) affected") mycursor.close() mydb.close()