On Thu, Jun 18, 2009 at 9:03 PM, Serdar Tumgoren<zstumgo...@gmail.com> wrote:
> When I run this code: > > <<< snip >>> > for line in infile: > cleanline = translate_code(line) > newline = strip_html(cleanline) > outfile.write(newline) > <<< snip >>> > > ...I receive the below traceback: > > Traceback (most recent call last): > File "htmlcleanup.py", line 112, in <module> > outfile.write(newline) > UnicodeEncodeError: 'ascii' codec can't encode character u'\xf1' in > position 21: ordinal not in range(128) OK, so newline is unicode, outfile.write() wants a plain string. What encoding do you want outfile to be in? Try something like outfile.write(newline.encode('utf-8')) or use the codecs module to create an output that knows how to encode. Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor