On Tue, Apr 7, 2009 at 2:59 PM, Pirritano, Matthew <mpirrit...@ochca.com> wrote:

> Traceback (most recent call last):
>
>   File "C:\Projects\unicode_convert.py", line 8, in <module>
>
>     outp.write(outLine.strip()+'\n')
>
> UnicodeEncodeError: 'ascii' codec can't encode characters in position
> 640-641: ordinal not in range(128)
>
> Should I be worried about this. And where does this message indicate that
> the error is. And what is the error?

The error is that your source file contains characters that are not in
the Ascii set; in particular a character with value 128 was found at
location 640 in some unknown line.

Yes, you should be worried; the processing aborted at that point.

The error happens during an implicit conversion from unicode to ascii
within the write() call. What you have is equivalent to
  outp.write(outline.strip().encode('ascii') + '\n')

You can the encoder to ignore errors or replace them with ? by adding
the parameter
  errors = 'ignore'
or
  errors = 'replace'
to the encode() call, e.g.
  outp.write(outline.strip().encode('ascii', errors='replace') + '\n')

If you want to know the line which contains the error you will have to
modify your program to keep track of line numbers and trap and report
errors.

Kent
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to