data=query to fetch data from MySQL with for loop .
fileName="abcd/2022"
fieldNames = [
"SL NUMBER"
"NAME",
"PLACE",
"AGE"
]
with open(fileName,append_write) as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=fieldNames)
writer.writeheader()
writer.writerows(data)
After generating csv file its look like this,
SL NUMBER NAME PLACE AGE
xyz delhi 15
pqr mumbai 23
lmn karnataka 21
csv is generated for "NAME","PLACE","AGE" these columns and all datas is coming fine with new lines.now the requirement is for "SL NUMBER" need to be auto incremented based on entries how can i achieve that. Thanks for inputs