循环替换字典中的None值:
class Gsxt: """ """ def __init__(self, company_name, city): pass def replace_dict(self, tmp_dict_or_list): if isinstance(tmp_dict_or_list, dict): for k, v in tmp_dict_or_list.items(): if isinstance(v, (dict, list)): tmp_dict_or_list[k] = self.replace_dict(v) else: if v is None: tmp_dict_or_list[k] = "" elif isinstance(tmp_dict_or_list, list): for i, value in enumerate(tmp_dict_or_list): if isinstance(value, (dict, list)): tmp_dict_or_list[i] = self.replace_dict(value) else: if value is None: tmp_dict_or_list[i] = "" return tmp_dict_or_list