Skip to content

Error when locale does use a special character for the decimal #6

Description

After setting up the locale to fr_FR.UTF-8 using raspi-configand launching the script, I get the following error :

pi@raspberrypi:~nas-kit $ python3 main/raspi_omv_main.py
Exception in thread Thread-1
Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 917, in _boostrap_inner
    self.run()
  File "/usr/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "main/raspi_omv_main.py", line 312, in main
    page(current_page)
  File "/home/pi/nas-kit/main/page.py", line 76, in __call__
    eval(cmd)
  File "<string>", line 1, in <module>
  File "/home/pi/nas-kit/main/page.py", line 99, in page_1_update
    pi_msg = pi_read()
  File "/home/pi/nas-kit/main/page.py", line 150, in pi_read
    "cpu_usage": cpu_usage(),
  File "/home/pi/nas-kit/main/page.py", line 106, in cpu_usage
    result = round(100 - float(result), 2)
ValueError: could not convert string to float: '80,35'

The problem seems to come fram the fact that the french locale use , as a decimal separator, and not ..
The workaround is to revert back to en_US.UTF-8 locale, but it should be possible to handle this problem using the locale library.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions