def read_code(filename):
    '读取code编码文件并输出为字典格式\n    1、支持json格式\n    2、支持本包规定的xlsx格式\n    see alse to_code\n    '
    file_type = os.path.splitext(filename)[1][1:]
    if (file_type == 'json'):
        import json
        code = json.load(filename)
        return code
    d = pd.read_excel(filename, header=None)
    d = d[d.any(axis=1)]
    d.fillna('NULL', inplace=True)
    d = d.as_matrix()
    code = {}
    for i in range(len(d)):
        tmp = d[(i, 0)].strip()
        if (tmp == 'key'):
            code[d[(i, 1)]] = {}
            key = d[(i, 1)]
        elif (tmp in ['qlist', 'code_order']):
            ind = np.argwhere((d[(i + 1):, 0] != 'NULL'))
            if (len(ind) > 0):
                j = ((i + 1) + ind[0][0])
            else:
                j = len(d)
            tmp2 = list(d[i:j, 1])
            for i in range(len(tmp2)):
                if isinstance(tmp2[i], str):
                    tmp2[i] = tmp2[i].strip()
            code[key][tmp] = tmp2
        elif (tmp in ['code', 'code_r']):
            ind = np.argwhere((d[(i + 1):, 0] != 'NULL'))
            if (len(ind) > 0):
                j = ((i + 1) + ind[0][0])
            else:
                j = len(d)
            tmp1 = list(d[i:j, 1])
            tmp2 = list(d[i:j, 2])
            for i in range(len(tmp2)):
                if isinstance(tmp2[i], str):
                    tmp2[i] = tmp2[i].strip()
            code[key][tmp] = dict(zip(tmp1, tmp2))
        elif ((tmp != 'NULL') and (d[(i, 2)] == 'NULL') and ((i == (len(d) - 1)) or (d[((i + 1), 0)] == 'NULL'))):
            ind = np.argwhere((d[(i + 1):, 0] != 'NULL'))
            if (len(ind) > 0):
                j = ((i + 1) + ind[0][0])
            else:
                j = len(d)
            if (i == (len(d) - 1)):
                code[key][tmp] = d[(i, 1)]
            else:
                tmp2 = list(d[i:j, 1])
                for i in range(len(tmp2)):
                    if isinstance(tmp2[i], str):
                        tmp2[i] = tmp2[i].strip()
                code[key][tmp] = tmp2
        elif ((tmp != 'NULL') and (d[(i, 2)] != 'NULL') and ((i == (len(d) - 1)) or (d[((i + 1), 0)] == 'NULL'))):
            ind = np.argwhere((d[(i + 1):, 0] != 'NULL'))
            if (len(ind) > 0):
                j = ((i + 1) + ind[0][0])
            else:
                j = len(d)
            tmp1 = list(d[i:j, 1])
            tmp2 = list(d[i:j, 2])
            for i in range(len(tmp2)):
                if isinstance(tmp2[i], str):
                    tmp2[i] = tmp2[i].strip()
            code[key][tmp] = dict(zip(tmp1, tmp2))
        elif (tmp == 'NULL'):
            continue
        else:
            code[key][tmp] = d[(i, 1)]
    return code
读取code编码文件并输出为字典格式
1、支持json格式
2、支持本包规定的xlsx格式
see alse to_code
def read_code(filename):
    '读取code编码文件并输出为字典格式\n    1、支持json格式\n    2、支持本包规定的xlsx格式\n    see alse to_code\n    '
    file_type = os.path.splitext(filename)[1][1:]
    if (file_type == 'json'):
        import json
        code = json.load(filename)
        return code
    d = pd.read_excel(filename, header=None)
    d = d[d.any(axis=1)]
    d.fillna('NULL', inplace=True)
    d = d.as_matrix()
    code = {}
    for i in range(len(d)):
        tmp = d[(i, 0)].strip()
        if (tmp == 'key'):
            code[d[(i, 1)]] = {}
            key = d[(i, 1)]
        elif (tmp in ['qlist', 'code_order']):
            ind = np.argwhere((d[(i + 1):, 0] != 'NULL'))
            if (len(ind) > 0):
                j = ((i + 1) + ind[0][0])
            else:
                j = len(d)
            tmp2 = list(d[i:j, 1])
            for i in range(len(tmp2)):
                if isinstance(tmp2[i], str):
                    tmp2[i] = tmp2[i].strip()
            code[key][tmp] = tmp2
        elif (tmp in ['code', 'code_r']):
            ind = np.argwhere((d[(i + 1):, 0] != 'NULL'))
            if (len(ind) > 0):
                j = ((i + 1) + ind[0][0])
            else:
                j = len(d)
            tmp1 = list(d[i:j, 1])
            tmp2 = list(d[i:j, 2])
            for i in range(len(tmp2)):
                if isinstance(tmp2[i], str):
                    tmp2[i] = tmp2[i].strip()
            code[key][tmp] = dict(zip(tmp1, tmp2))
        elif ((tmp != 'NULL') and (d[(i, 2)] == 'NULL') and ((i == (len(d) - 1)) or (d[((i + 1), 0)] == 'NULL'))):
            ind = np.argwhere((d[(i + 1):, 0] != 'NULL'))
            if (len(ind) > 0):
                j = ((i + 1) + ind[0][0])
            else:
                j = len(d)
            if (i == (len(d) - 1)):
                code[key][tmp] = d[(i, 1)]
            else:
                tmp2 = list(d[i:j, 1])
                for i in range(len(tmp2)):
                    if isinstance(tmp2[i], str):
                        tmp2[i] = tmp2[i].strip()
                code[key][tmp] = tmp2
        elif ((tmp != 'NULL') and (d[(i, 2)] != 'NULL') and ((i == (len(d) - 1)) or (d[((i + 1), 0)] == 'NULL'))):
            ind = np.argwhere((d[(i + 1):, 0] != 'NULL'))
            if (len(ind) > 0):
                j = ((i + 1) + ind[0][0])
            else:
                j = len(d)
            tmp1 = list(d[i:j, 1])
            tmp2 = list(d[i:j, 2])
            for i in range(len(tmp2)):
                if isinstance(tmp2[i], str):
                    tmp2[i] = tmp2[i].strip()
            code[key][tmp] = dict(zip(tmp1, tmp2))
        elif (tmp == 'NULL'):
            continue
        else:
            code[key][tmp] = d[(i, 1)]
    return code