Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoding Help #20

Closed
Budapresst opened this issue Dec 2, 2019 · 3 comments
Closed

Encoding Help #20

Budapresst opened this issue Dec 2, 2019 · 3 comments
Labels

Comments

@Budapresst
Copy link

Hi...
I'm having a problem with encoding and I'm not not too familiar with Python, so I'm hoping you have a second to help me out.

I'm using your xlsb to csv example verbatim on a workbook that has lots of foreign (Hungarian) characters. When it hits the first special character, I get this error: UnicodeEncodeError: 'ascii' codec can't encode character u'\xc1' in position 1: ordinal not in range(128)

I'm expecting that the c.v in this line: writer.writerow([c.v for c in row]) needs to be encode before writing it to the file, but I don't know how to implement the encoding. I tried some stuff like c.v.encode('utf-8') but, of course, it didn't work. Could you point me in the right direction?

Thanks!
-Alec

@willtrnr
Copy link
Owner

willtrnr commented Dec 2, 2019

I assume you're using Python 2.x. This is happening because the built-in csv module doesn't really support unicode.

The best way to fix this would be to upgrade to Python 3, if that's possible for you.

Otherwise, make sure you open the file in wb mode and your c.v.encode('utf-8') should work I think.

@willtrnr
Copy link
Owner

willtrnr commented Dec 2, 2019

I'll close this since it's not directly related to the project, but comments will stay open and we can still use it for discussion.

@willtrnr willtrnr closed this as completed Dec 2, 2019
@Budapresst
Copy link
Author

Thank you for the help, Will!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants