我正在查询具有某些特定列的表,并希望将每个值存储在不同的全局变量中。
当我只尝试查询一行时,我可以将值存储在全局变量中,但是当我将LIMIT增加超过一个时,我的代码将不起作用。
query = Select event, date, city, country from Table LIMIT 1;
event = ""
date = ""
city = ""
country = ""
for row in cur.execute(query):
global event
global date
global city
global country
event, date, city, country = [row[i] for i in (0, 1, 2, 3)]
我想在每次迭代中将新值存储在全局变量中。结果应如下所示:-
Output: (On 1st Iteration)
event ="ABC"
date ="12 June"
city ="Delhi"
country ="India"
Output: (On 2nd Iteration)
event ="XYZ"
date ="2 May"
city ="New York"
country ="USA"
Output: (On 3rd Iteration)
event ="DDD"
date ="15 Sep"
city ="Tokyo"
country ="Japan"