def _str_to_num(val):
 try:
  num = int(val)
 except ValueError:
  num = float(val)
 return num

def _str_to_num ( val ) : try : num = int ( val ) except ValueError : num = float ( val ) return num
converts a given string to either an int or a float if necessary .