-
Notifications
You must be signed in to change notification settings - Fork 468
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
Defining miligram per cent (mg%) #1717
Comments
Not sure but this might have been solved in master already while introducing % and ppm (not released yet). Would you like to try master branch to confirm? |
I had quite some fun integrating currency symbols into my Pint application:
One of the challenges is that if/when the tokenizer sees a non-Pythonic character, it throws a fit (ERROR_TOKEN). So I had to use pre-processors. Granted, % is a pythonic character, but a binop, not a postfix unop. I haven't yet tried the new % handling code in the upcoming release (I'm still waiting for word on the changes I've made for handling uncertainties, and I don't want to mess up my existing PR by merging changes that don't belong to that PR). Pre-processors are a powerful way to address parsing problems like this. |
Thanks @lafrech - it looks like the new version supports useage of "%" in such definitions! |
Hi! Great package 💪
I'm currently exploring Pint possibilities in medical field and stumbled upond a problem with adding support for "mg%" measure.
It's rather depricated, but in some cases still in use ( [https://en.wikipedia.org/wiki/Milligram_per_cent] )
The problem is that I can't simply register "mg%" unit symbol, due to definition error
DefinitionSyntaxError('missing unary operator "%s"' % op_text)
.I tried different approaches (#1402, #379, #429) but non of them works in my case and in most cases it somehow ends up with the error above.
One thing that worked in some cases was to append the definition to default_en.txt as:
miligrampercent = mg/dL = mg%
But even then ureg checkup or
.to(ureg['mg%'])
doesn't work (same error).I use the packeage to convert quantities based on provided string and in almost all cases it works perfectly except this one. Seem like I can simply replace string from "mg%" to eg "miligrampercent" before defining it in Pint and again, after obtaining the result, replace "miligrampercent" to "mg%" in some caseses, but it doesn't looks like the most elegent solution.
The text was updated successfully, but these errors were encountered: