[Tutor] Urgent: unicode problems writing CSV file
Michael Selik
michael.selik at gmail.com
Wed Jun 8 13:13:10 EDT 2016
On Wed, Jun 8, 2016 at 12:53 PM Alex Hall <ahall at autodist.com> wrote:
> All,
> I'm working on a project that writes CSV files, and I have to get it done
> very soon. I've done this before, but I'm suddenly hitting a problem with
> unicode conversions. I'm trying to write data, but getting the standard
> cannot encode character: ordinal not in range(128)
>
Have you tried ignoring invalid characters?
>>> data = b'\x30\x40\xff\x50'
>>> text = data.decode('utf-8')
Traceback ... UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff
>>> text = data.decode('utf-8', 'ignore')
>>> print(text)
0 at P
BTW, most programming volunteers don't like responding to things marked
"Urgent". It's probably not really urgent unless someone's life is in
danger.
More information about the Tutor
mailing list