Skip to content

Reset locale setting in qtconsole #3103

@phillipberndt

Description

@phillipberndt

The setlocale() man-page states that

On startup of the main program, the portable "C" locale is selected as default.

The QT backend (or PyQT or QT itself) apparently makes a call to setlocale() according to my computer's settings:

In [1]: from ctypes import CDLL, c_char_p
In [2]: c = CDLL("libc.so.6")
In [3]: c.setlocale.restype = c_char_p
In [4]: c.setlocale(0)
Out[4]: 'de_DE.UTF-8'

I noticed this when I tried to use Cantera (a chemical kinetics library with a Python interface) from IPython and got different results depending on whether I used the QTConsole or not. Turns out they make a call to atof()/strtod() without overriding the locale setting beforehand, which they probably do because they rely on the statement from the man-page and figure that a user willingly overriding this value would know what he is doing.

In my opinion, IPython's state after startup should not depend on the choice of the frontend. I therefore suggest that you either reset the locale setting (must be done using setlocale(), updating the environment is not enough) after initializing QT or, alternatively, call setlocale(0, "") when the QT-backend is not used.

(I will also file a bug against Cantera, proposing to issue a warning when an unexpected locale is set.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions