Jassin
Jassin

Reputation: 13

open file with csv.reader in utf-8

i try to open a file in utf-8 and step trough the file with the csv.reader:

    with codecs.open(sap_file, "rb", "utf-8") as in_file:
        #self.logger.debug("open")
        self.reader = csv.reader(in_file,delimiter=";")
        for row in self.reader:
            self.pnrs[(row[1])]={}
        for rows in self.reader:
            self.pnrs[rows[1]][rows[3]]=rows[4]

But here is my traceback:

for row in self.reader:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 38:  ordinal not in range(128)

Somebody here with some tips?

Upvotes: 1

Views: 114

Answers (1)

zer0uno
zer0uno

Reputation: 8030

I think you are opening the file in the wrong way, try open(sap_file, "rb") instead of codecs.open(sap_file, "rb", "utf-8").

Also read here.

Upvotes: 1

Related Questions