0

Click here to see screenshot

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')
  • 1
    Google + (unicode error) 'unicodeescape' = http://stackoverflow.com/questions/1347791/unicode-error-unicodeescape-codec-cant-decode-bytes-cannot-open-text-file (that is, search the first little part of the error message). – Koebmand STO Mar 10 '16 at 02:44

1 Answers1

2

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.

Community
  • 1
  • 1
Tadhg McDonald-Jensen
  • 20,699
  • 5
  • 35
  • 59