icinga2-checks/checker/types.py

21 lines
411 B
Python

from typing import Union
def try_float(value: str) -> float:
try:
return float(value)
except:
pass
try:
return float(int(value))
except:
pass
raise ValueError(f"Could not convert {value} to float or int")
def try_int(value: str) -> int:
try:
return int(value)
except:
raise ValueError(f"Could not convert {value} to float or int")