'cp932' codec can't encode character '\u98c8' in position 32: illegal multibyte sequence

Viewed 6896

I want to write strings to a file but get a UnicodeEncodeError.

      7 with open('testfile.txt', 'w') as f:
      8     for item in list:
----> 9         f.write("%s\n" % item)

UnicodeEncodeError: 'cp932' codec can't encode character '\u98c8' in position 32: illegal multibyte sequence

How to fix this?

My program gets a text from web pages and saves them as a .txt file.

1 Answers
Related