split_units

typhon.utils.split_units(value)[source]

Splits a string into float number and potential unit

References

Taken from https://stackoverflow.com/a/30087094

Parameters:

value – String with number and unit.

Returns

A tuple of a float and unit string.

Examples

>>> split_units("2GB")
(2.0, 'GB')
>>> split_units("17 ft")
(17.0, 'ft')
>>> split_units("   3.4e-27 frobnitzem ")
(3.4e-27, 'frobnitzem')
>>> split_units("9001")
(9001.0, '')
>>> split_units("spam sandwhiches")
(0, 'spam sandwhiches')
>>> split_units("")
(0, '')