-
Notifications
You must be signed in to change notification settings - Fork 477
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
Order units #2086
Comments
this is possible, here's an example. it needs adding to the documentation. >>> import pint
>>> ur = pint.UnitRegistry()
>>> ur.formatter.dim_order
('[substance]', '[mass]', '[current]', '[luminosity]', '[length]', '[]', '[time]', '[temperature]')
>>>
>>> from pint.delegates.formatter._compound_unit_helpers import sort_by_dimensionality
>>> ur.formatter.default_sort_func = sort_by_dimensionality
>>>
>>> Q_=ur.Quantity
>>> res=Q_(1,"m")*Q_(1,"N")
>>> str(res)
'1 newton * meter'
>>>
>>> ur.formatter.dim_order = ('[temperature]', '[time]', '[]', '[length]', '[luminosity]', '[current]', '[mass]', '[substance]')
>>>
>>> Q_=ur.Quantity
>>> res=Q_(1,"m")*Q_(1,"N")
>>> str(res)
'1 meter * newton'
>>> |
Thank you very much for your prompt reply; I tried it with your proposal and it worked perfectly, but when I tried it with ‘inch’ and ‘kip’ and it stopped working, the ‘inch’ is always put in front and I don't understand why. |
the function sort_by_dimensionality ordered based on the index of the dimensionality of each unit in the dim_order tuple, see
you could write your own function to sort in the way you desire. see the sort_by_dimensionality for an example this would be something good to add to pint; the functionality to provide a list of units and a function that sorts based on that list, analagous to the dim_order |
Hi, when I multiply units of force with length or its simplification results in force times length the result always gives in order length times force, I would like that to change because I am using handcalcs and generate reports so it is unusual to read length times force, when I am used to it being force times length. Attached is the configuration.
The text was updated successfully, but these errors were encountered: