Q:

Python : open csv files from a list and convert them into xls

I'd like to open multiple csv files from a list and then convert them into xls files.
I made that code :
import sys, csv, xlwt

files = ['/home/julien/excel/csv/ABORD2.csv']

for i in files:
    f=open(i, 'rb')
    g = csv.reader ((f), delimiter=";")
    workbook=xlwt.Workbook()
    sheet= xlwt.Workbook()
    sheet = workbook.add_sheet("Sheet 1")

    for rowi, row in enumerate(g):
        for coli, value in enumerate(row):
            sheet.write(rowi,coli,value)
        workbook.save(i + ".xls")

My xls files are created.But in both of them I only have the path of the xls.
For example for the file ABORD.xls only the following expression is written :
'/home/julien/excel/csv/ABORD2.xls'

Would you have any suggestions ?

A:

Sir, you're creating two Workbooks unnecessairly and you're saving the workbook with wrong identation
import csv, xlwt

files = ['test.csv']

for i in files:
    f=open(i, 'rb')
    g = csv.reader ((f), delimiter=";")
    wbk= xlwt.Workbook()
    sheet = wbk.add_sheet("Sheet 1")

    for rowi, row in enumerate(g):
        for coli, value in enumerate(row):
            sheet.write(rowi,coli,value)

    wbk.save(i + '.xls')

