(s, try_types=(int, float))
return s
Try to coerce string to Python numeric type, return None if empty.
Try to coerce string to Python numeric type, return None if empty.
Try to coerce string to Python numeric type return None if empty .
def try_coerce_to_num(s, try_types=(int, float)):
  """Try to coerce string to Python numeric type, return None if empty."""
  if not s:
    return None
  for try_type in try_types:
    try:
      return try_type(s.rstrip("UuFf"))
    except (ValueError, AttributeError):
      continue
  return s
def try_coerce_to_num ( s , try_types = ( int , float ) ) : if not s : return None for try_type in try_types : try : return try_type ( s . rstrip ( "UuFf" ) ) except ( ValueError , AttributeError ) : continue return s