Hpw to add sl number to the generated csv file

28 Views Asked by At
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

0

There are 0 best solutions below