[Tutor] UnicodeDecodeError

Mats Wichmann mats at wichmann.us
Mon Mar 16 11:15:25 EDT 2020


On 3/16/20 8:11 AM, thehouse.be--- via Tutor wrote:
> 
>>>> I am trying to work with .csv files in order to analyse data which comes from a Google Forms survey.
>>>> Idea is to handle the raw data, do some statistical analysis and make a report.
>>>>
>>>>
> When writing to a text file I get the same error:
> Traceback (most recent call last):
> File "/Users/chrisvanroey/mu_code/collab_comment_decoder.py", line 79, in <module>
> p.write_text('- ' + (cel))
> File "/Users/travis/build/mu-editor/mu_portable_python_macos/python/lib/python3.6/pathlib.py", line 1214, in write_text
> UnicodeEncodeError: 'ascii' codec can't encode character '\xeb' in position 144: ordinal not in range(128)
> 
> 
> So probably I have also to put  ‘utf-8’ somewhere in the p.write_text code.
> But I can’t find where….

You set it in the open, then all the methods on the file (or Path object
in your case) respect it.

See the docs:

Path.open(mode='r', buffering=-1, encoding=None, errors=None, newline=None)




More information about the Tutor mailing list