首页 > 编程语言 >python中的KeyError报错

python中的KeyError报错

时间:2023-02-17 12:11:32浏览次数:39  
标签:return resCode python blank KeyError util 报错 str resultJson

from util import str_util
#业务逻辑:兼容不同的结构体:resCode转化数据
#检查字典中是否存在键 if 'resCode' not in resultJson
    if 'resCode' not in resultJson:
        if 'returnCode' in resultJson:
            resCode = resultJson["returnCode"]
            if str_util.is_not_blank(resCode) and resCode == "1":
                resCode = "000000"
        
        if 'status' in resultJson:
            resCode = resultJson["status"]
            if resCode == 20000:
                resCode = "000000"
    else:
        resCode = resultJson["resCode"]
        

str_util.py
def is_blank(str: str):
    if str and str.strip():
        return False
    return True


def is_not_blank(str: str):
    return is_blank(str) == False

 

标签:return,resCode,python,blank,KeyError,util,报错,str,resultJson
From: https://www.cnblogs.com/oktokeep/p/17129719.html

相关文章