str_to_value

sofia_redux.toolkit.utilities.func.str_to_value(text)[source]

Convert a string to an int or float. If the format is not recognized, the original input will be returned.

Parameters:
textstr

May be an integer (e.g. “123”), a decimal (“1.23”), or scientific notation (“1.2e-3”).

Returns:
int or float

Examples

>>> from sofia_redux.toolkit.utilities.func import str_to_value
>>> print(str_to_value("4.32e-1"))
0.432