В командной строке Windows настроено использование кодовой страницы 437 (cp437
), а символ евро не определен в этой кодировке. Вы можете изменить кодовую страницу на 1252, которая поддерживает символ:
C:\>py -2
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print u'\u20ac'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\dev\Python27\lib\encodings\cp437.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u20ac' in position 0: character maps to <undefined>
>>> ^Z
C:\>chcp 1252
Active code page: 1252
C:\>py -2
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print u'\u20ac'
€
Лучшая альтернатива - перейти на Python 3.6 или более позднюю версию, которая использует API-интерфейсы Windows Unicode для прямой записи в консоль, минуя проблемы с кодировкой:
C:\>py -3
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print('\u20ac')
€