I have a dictionary let's say my_dic
and I want to append it to a list through a loop modifying the value of my_dic
, here is the example and it works by the way:
my_lst = []
my_dic = {
'hello': 'World'
}
my_lst.append(my_dic)
my_dic = {
'hello': 'World 2'
}
my_lst.append(my_dic)
and it returns [{'hello': 'World'}, {'hello': 'World 2'}]
which is what I want and it works correctly. But there is another place where the same thing doesn't work.
query = """
SELET * FROM some_table
"""
connection = mysql.connector.connect(user=user,
password=password,
host=host,
database=database)
cursor = connection.cursor(dictionary=True)
cursor.execute(query)
rows=cursor.fetchall()
data= []
tempRow = rows[0]
tempRow['RS'] = 'old value'
data.append(tempRow)
tempRow = rows[0]
tempRow['RS'] = '1'
data.append(tempRow)
pp(data)
which returns data
like this:
[{'RS': '1'}, {'RS': '1'}]
however, I expect it like this:
[{'RS': 'old value'}, {'RS': '1'}]
Edited: I have removed the loop.