Skip to content
Advertisement

Problems with decoding from command prompt [python]

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:

JavaScript

It works perfectly in IDLE, but when I save my code and run it from the command prompt, it raises error, specifically:

JavaScript

In my particular case, the text is “gemäßigt”, and in the beginning of .py code I put something like

JavaScript

By the way, my OS is Windows, in Russian. Does anybody have an idea what is my problem?

Best, Alex

Advertisement

Answer

Your console uses the DOS codepage 866 which doesn’t have the character symbols for ä or ß, causing the error.

You could try .encoding('cp866', errors='replace') your string before output, replacing all the characters not supported by your terminal by ?s.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement