Reputation: 29
I am trying to convert a CSV to XLS using Python 3.5.1 I have attached a picture to show the issue
import csv, xlwt
files = ["C:\Users\Office\Documents"]
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')
Upvotes: 0
Views: 123
Reputation: 21453
Following @KoebmandSTO's advice you may want to try this.
you are using backslashes in the string that are normally used to escape special characters like \n
, to prevent this behaviour use r"..."
:
files = [r"C:\Users\Office\Documents"]
see this answer for better explanation on what the r
does.
or backslash escape the backslash with \\
:
files = ["C:\\Users\\Office\\Documents"]
since the \
is a special character that needs to be escaped.
Upvotes: 2