def load_list(csv, str_ok=False): """ load a list from a string """ if csv[0] == '[' and csv[-1] == ']': csv = csv[1:-1] my_list = csv.split(',') for n, val in enumerate(my_list): if core.is_number(val): if core.is_int(val): my_list[n] = int(n) else: my_list[n] = float(n) if str_ok: if len(my_list) == 1: my_list = my_list[0] return my_list
def load_list(csv, str_ok=False): """ load a list from a string """ if csv[0] == '[' and csv[-1] == ']': csv = csv[1:-1] my_list = csv.split(',') for n, val in enumerate(my_list): if core.is_number(val): if core.is_int(val): my_list[n] = int(n) else: my_list[n] = float(n) if str_ok: if len(my_list)==1: my_list = my_list[0] return my_list
def load_unknown(str_in, single_ok=False): """ load a json string with an unknown type """ try: # This will work for a dictionary or a list='[1,2,"a",...]' but not a string or a number # or a csv list='1,2,3,"a",...' val_out = json.loads(str_in) except (ValueError, TypeError) as e: if single_ok: if core.is_number(str_in): if core.is_int(str_in): val_out = int(str_in) else: val_out = float(str_in) else: val_out = str_in else: raise ToyzIoError("Toyz expected a dict or list for " + str_in) return val_out
def load_unknown(str_in, single_ok=False): """ load a json string with an unknown type """ try: # This will work for a dictionary or a list='[1,2,"a",...]' but not a string or a number # or a csv list='1,2,3,"a",...' val_out = json.loads(str_in) except (ValueError, TypeError) as e: if single_ok: if core.is_number(str_in): if core.is_int(str_in): val_out = int(str_in) else: val_out = float(str_in) else: val_out = str_in else: raise ToyzIoError("Toyz expected a dict or list for "+str_in) return val_out