21 lines
411 B
Python
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")
|