我不能把deC定义为一个单位.
进入后
import pint
u=pint.UnitRegistry()
当声明1*u.degC
时,它输出1 degree_Celsius
.看起来还可以.
当我声明2*u.degC
时,它输出以下错误...
>>> 2*u.degC
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "\Lib\site-packages\pint\facets\plain\unit.py", line 147, in __mul__
return self._REGISTRY.Quantity(1, self._units) * other
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
File "\Lib\site-packages\pint\facets\plain\quantity.py", line 1010, in __mul__
return self._mul_div(other, operator.mul)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "\Lib\site-packages\pint\facets\plain\quantity.py", line 103, in wrapped
return f(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^
File "\Lib\site-packages\pint\facets\plain\quantity.py", line 77, in wrapped
result = f(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^
File "\Lib\site-packages\pint\facets\plain\quantity.py", line 958, in _mul_div
raise OffsetUnitCalculusError(self._units, getattr(other, "units", ""))
pint.errors.OffsetUnitCalculusError: Ambiguous operation with offset unit (degree_Celsius). See https://pint.readthedocs.io/en/stable/user/nonmult.html for guidance.
有人能告诉我为什么会是这样吗?
我确实阅读了文档,并在浏览器中进行了一些搜索. 不幸的是,在解决方向上没有任何进展.
期望值:
- 要在具有多个幅值含义的Python中使用deC单位定义,而不仅仅是1.
- 使用DECC单位别名进行计算.