[issue45232] ascii codec is used by default when LANG is not set
Olivier Delhomme
report at bugs.python.org
Fri Sep 17 10:54:29 EDT 2021
Olivier Delhomme <olivier.delhomme at cea.fr> added the comment:
>> Hi Marc-Andre,
>>
>> Please note that setting PYTHONUTF8 with "export PYTHONUTF8=1":
>>
>> * Is external to the program and user dependent
>> * It does not seems to work on my use case:
>>
>> $ unset LANG
>> $ export PYTHONUTF8=1
>> $ python3
>> Python 3.6.4 (default, Jan 11 2018, 16:45:55)
>> [GCC 4.8.5] on linux
>> Type "help", "copyright", "credits" or "license" for more information.
>> >>> machaine='ééééhelp me if you can'
>> File "<stdin>", line 0
>>
>> ^
>> SyntaxError: 'ascii' codec can't decode byte 0xc3 in position 10: ordinal not in range(128)
>
> UTF-8 mode is only supported in Python 3.7 and later:
>
> https://docs.python.org/3/whatsnew/3.7.html#whatsnew37-pep540
Oh. Thanks.
$ unset LANG
$ export PYTHONUTF8=1
$ python3
Python 3.7.5 (default, Dec 24 2019, 08:52:13)
[GCC 4.8.5] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> machaine='ééééhelp me if you can'
>>>
From the code point of view:
$ unset LANG
$ unset PYTHONUTF8
$ python3
Python 3.7.5 (default, Dec 24 2019, 08:52:13)
[GCC 4.8.5] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ['PYTHONUTF8'] = '1'
>>> machaine='ééééhelp me if you can'
>>>
Even better:
$ unset LANG
$ unset PYTHONUTF8
$ python3
Python 3.7.5 (default, Dec 24 2019, 08:52:13)
[GCC 4.8.5] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> machaine='ééééhelp me if you can'
>>>
Works as expected. Thank you very much. You can close this bug report.
Regards,
Olivier.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45232>
_______________________________________
More information about the Python-bugs-list
mailing list