Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locales which use decimal commas instead of dots break output parsing #1

Closed
ByteCommander opened this issue Jul 22, 2016 · 2 comments
Closed

Comments

@ByteCommander
Copy link
Contributor

My locale specifies German number formatting i.e. two and a half will be "2,5" instead of "2.5".

This breaks the part of your script which is responsible for parsing the output of upower because it expects only digits and a dot in floating point number literals.

You could either prefix the upower command with LANG=C to run it with a default English locale or translate commas into dots in the output string before parsing it.

Here's the exact traceback:

$ powerflow-indicator 
/usr/local/bin/powerflow-indicator:39: PyGIWarning: AppIndicator3 was imported without specifying a version first. Use gi.require_version('AppIndicator3', '0.1') before import to ensure that the right version gets loaded.
  from gi.repository import AppIndicator3 as appindicator
Traceback (most recent call last):
  File "/usr/local/bin/powerflow-indicator", line 172, in <module>
    main()
  File "/usr/local/bin/powerflow-indicator", line 168, in main
    indicator = LockKeyStatusIndicator(args.amps)
  File "/usr/local/bin/powerflow-indicator", line 59, in __init__
    self.update_label()
  File "/usr/local/bin/powerflow-indicator", line 153, in update_label
    label_text = self.get_power_info()[0]
  File "/usr/local/bin/powerflow-indicator", line 138, in get_power_info
    1000 * float(energy_rate[:-1]) / float(voltage[:-1]), 4)
ValueError: invalid literal for float(): 17,305
@SergKolo
Copy link
Owner

@ByteCommander pushed a fix. I'm overriding everything with LC_ALL variable. Tested on Chinese locale, seems to work. Let me know if it works for you

@ByteCommander
Copy link
Contributor Author

The locale issue seems fixed, no more errors here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants