Re: Unable to run print('Réussi') on windows and on linux

wxjmfauth at gmail.com wxjmfauth at gmail.com
Fri Aug 15 04:25:28 EDT 2014


Le jeudi 14 août 2014 17:21:41 UTC+2, Steven D'Aprano a écrit :
> 
> * Fix your system to use UTF-8 by default.
> 
> 

%%%%%

Sorry, but no. This is not a correct way of working.


>>> u = 'abc需αб'
>>> u; print(u)
'abc需αб'
abc需αб
>>> sys.stdout.encoding = 'cp437'
>>> print(u)
Traceback (most recent call last):
  File "<eta last command>", line 1, in <module>
  File "D:\jm\jmpy\eta\eta41beta1\etastdio.py", line 193, in write
    s = s.encode(self.pencoding).decode('cp1252')
  File "c:\python32\lib\encodings\cp437.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode characters in position 4-5: 
character maps to <undefined>
>>> print(u.encode(sys.stdout.encoding, 'replace'))
abcé??α?
>>> sys.stdout.encoding = 'utf-16-le'
>>> print(u)
a b c é S¬ ±1
 
>>> print(u.encode(sys.stdout.encoding, 'replace'))
abc需αб
 
>>> # etc


jmf




More information about the Python-list mailing list