[PyQt] QApllication changes the locale

Mads Ipsen mpi at comxnet.dk
Mon Jun 8 14:22:50 BST 2009


On a machine with

LANG=en_DK.UTF-8

The script

  import numpy

  # Now numpy is OK
  print "%s" % (numpy.float64(3.023423))
  print "%s %r" % (numpy.float32(3.023423), numpy.float32(3.023423))

prints

  3.023423
  3.02342 3.023423

Now change the script to

  import sys, os
  from PyQt4 import QtCore, QtGui, QtOpenGL

  # Set the LANG variable
  QT_APP = QtGui.QApplication(sys.argv)

  import numpy

  # Now numpy is OK
  print "%s" % (numpy.float64(3.023423))
  print "%s %r" % (numpy.float32(3.023423), numpy.float32(3.023423))

This prints

  3,023423
  3,02342 3,023423

which is very inconvenient in the application we are developing. Adding 
the line
 
  os.putenv('LANG', 'en_US.UTF-8')

before the QApplication is loaded solves the problem - but should this 
really happen?

Mads







More information about the PyQt mailing list