[New-bugs-announce] [issue45232] ascii codec is used by default when LANG is not set

Olivier Delhomme report at bugs.python.org
Fri Sep 17 08:30:29 EDT 2021


New submission from Olivier Delhomme <olivier.delhomme at cea.fr>:

$ python3 --version
Python 3.6.4

Setting LANG to en_US.UTF8 works like a charm

$ export LANG=en_US.UTF8   
$ 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'                                                                                                                                                                                
>>> print('{}'.format(machaine))                                                                                                                                                                                     
ééééhelp me if you can


Unsetting LANG shell variable fails the program:

$ unset LANG
$ 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)


Setting LANG inside the program does not change this behavior:

$ unset LANG
$ 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.
>>> import os
>>> os.environ['LANG'] = 'en_US.UTF8'
>>> 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)


Is this an expected behavior ? How can I force an utf8 codec ?

----------
components: Interpreter Core
messages: 402046
nosy: od-cea
priority: normal
severity: normal
status: open
title: ascii codec is used by default when LANG is not set
type: behavior
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45232>
_______________________________________


More information about the New-bugs-announce mailing list