-
Notifications
You must be signed in to change notification settings - Fork 476
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
How do you handle the "percent" unit ?... and some general questions about load_definitions #379
Comments
Finally made up a custom
|
generally you want to define as
This way it realizes that
|
The unit registry can't handle "%" as a unit, at least on my system. Pint 0.7.2 on Windows, Python 3.
Same error if I just say ureg('%') (with or without defining it). Specifically I get the AttributeError when I should get the UndefinedUnitError. |
I get the same error as @mcgibbon with Pint 0.7.2 running on Anaconda Python 3.5. I also don't see the formatting behaviour @tadhgmister describes: ureg = pint.UnitRegistry()
ureg.define('percent = 0.01*count = %')
x = 50 * ureg.percent
print(format(x,"~")) # Output: 50 [was expecting 50 %]
print(x + 1) # Output: 1.5 dimensionless
print(x.to('count')) # Output: 0.5 count |
I posted a workaround in #429. |
Closing. Feel free to reopen. |
I'm actually trying to integrate pint into pyhaystack, a project to connect Python to building automation systems. Pint would add great features to our project by allowing us to exploit the power of units given by the servers (temperature conversion, energy computation, etc.)
So as the title says : I didn't see any reference to a % unit in the default file. Is this something that can be handled ?
Our project use www.project-haystack.org units so I'm trying to create some kind of bridge between Pint and haystack so the units will be compatible. Most of the time, it works without problems but there are a lot of little edge cases that need some tweaks.
I tried to use
load_definitions
but I always get AttributeError: 'int' object has no attribute 'split' when I try to load the file... Maybe I'm doing something wrong.On a project like ours, would you suggest us to use our own file loaded in the module to isolate us from your default file ?
Or using a load_definition only ? (in that case, what if some day, duplicates appear ?)
Thanks for your answers.
The text was updated successfully, but these errors were encountered: