You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15 lines
209 B

  1. def safe_int(n):
  2. return _safe_cast(int, n)
  3. def safe_float(n):
  4. return _safe_cast(float, n)
  5. def _safe_cast(_type, val):
  6. try:
  7. return _type(val)
  8. except ValueError:
  9. return None