[Tutor] UnicodeDecodeError

thehouse.be at me.com thehouse.be at me.com
Sun Mar 15 17:04:25 EDT 2020


Dear Sibylle,

Thank you so much.
Adding encoding=‘utf-8’ is indeed the solution.

Extra info: I was working in the mu-editor when I encountered the problem.
I tried the same original commands (without ‘utf-8’) in Idle… and there it worked.

Again thank you for solving my problem,
Chris
On 15 Mar 2020, 20:05 +0100, Sibylle Koczian <nulla.epistola at web.de>, wrote:
> Am 15.03.2020 um 16:41 schrieb thehouse.be--- via Tutor:
> > I am a beginner, learning Python.
> > So sorry if my question is basic.
> >
> > 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 trying to convert the data into a listy of lists, I get a UnicodeDecodeError.
> >
> > This is what I do:
> >
> > > > > import csv
> > > > > exampleFile = open(‘example.csv’)
> > > > > exampleReader = csv.reader(exampleFile)
> > > > > exampleData = list(exampleReader)
> >
> > This last statement generates:
> > —————————————————————————————————————
> > UnicodeDecodeError Traceback (most recent call last)
> > <ipython-input-9-3817c0931c6f> in <module>
> > ----> 1 exampleData = list(exampleReader)
> > /Applications/mu-editor.app/Contents/Resources/python/lib/python3.6/encodings/ascii.pyc in decode(self, input, final)
> > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1798: ordinal not in range(128)
> >
> > I suppose there is a bizarre character somewhere in the file, but no idea where.
> > As we use accents and umlauts in our language, could that be the problem?
> > If that would be the problem, how to solve?
> >
>
> There doesn't need to be anything bizarre in the file - accents and
> umlauts suffice for ascii to choke. Opening the file with the right
> encoding given explicitly should help, for example for utf-8:
>
> exampleFile = open('example.csv', encoding='utf-8')
>
> HTH
> Sibylle
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list