I have the following problem. I have a german text saved in .txt UTF-8 format, and I'd like to print it out with python. Here's my code:
txt = open(filename, 'r').read()
print txt.decode('utf-8-sig')
It works perfectly in IDLE, but when I save my code and run it from the command prompt, it raises error, specifically:
UnicodeEncodeError: 'charmap' codec can't encode characters in position 3-4: cha
racter maps to <undefined>
In my particular case, the text is "gemäßigt", and in the beginning of .py code I put something like
# -*- coding: utf-8-sig -*-
By the way, my OS is Windows, in Russian. Does anybody have an idea what is my problem?
Best, Alex
import sysand thensys.stdout.encodingin the console?