Added to_tuple and from_tuple method to Quantity
This facilitate serializing and deserializing. If you have two function: serialize and deserialize, then your code will be as simple as this >>> serialized = serialize(q1.to_tuple()) >>> q2 = ureg.Quantity.from_tuple(deserialize(serialized))
This commit is contained in:
@@ -209,6 +209,13 @@ class _Quantity(SharedRegistryObject):
|
||||
|
||||
return self._dimensionality
|
||||
|
||||
@classmethod
|
||||
def from_tuple(cls, tup):
|
||||
return cls(tup[0], UnitsContainer(tup[1]))
|
||||
|
||||
def to_tuple(self):
|
||||
return self.m, tuple(self._units.items())
|
||||
|
||||
def compatible_units(self, *contexts):
|
||||
if contexts:
|
||||
with self._REGISTRY.context(*contexts):
|
||||
|
||||
Reference in New Issue
Block a user