1.引言

以前用过python脚本根据excel生成相关C语言代码,其实本质就是文件的读写,主要是逻辑问题,这次尝试将json文件生成C语言的结构体。

2.代码

这是一个json文件,生成这个结构体的本质是深度优先遍历,为了适应最复杂的情况,随便写了一个json文件(大家也可以根据需求自己改,我是自己写的,成功之后就去生产随机json的网站测试,目前没有啥问题,如果大家可以发现问题欢迎指出,在此感谢!)

{ 
    "BE1":{
        "apb_base_addr"  : "0x80000000",
        "stt_base_addr"  : "0x40000000",
        "size_type"      : {
            "REG": 64,
            "LUT": 64,
            "STT": 128
        },
        "module": [
            "BE_SYS", "BE_BIU",
            "DEC", "BLC", "LSC", "DGAIN", "AESTAT",
            "AWBSTAT", "AWB", "BDRC", "DM", "GAMMA",
            "RGBDITHER", "CSC", "SHP", "Y2RCSC", "CDS", "YUVDITHER","YUVDITHER"
        ],
        "nums": [
            1,2,6,4,3,6
        ],
        "tests" : [{"test1": 100, "test2": 200, "test3": 300 } ,
                   {"test1": 400, "test2": 500, "test3": 600 }],

        "repeat":{
                "a1" : {"test1": 100, "test2": 200, "test3": 300 } ,
                "b1" : {"test4": 400, "test5": 500, "test6": 600 }
        }
    },
    "PE1" : 0,

    "BE2":{
        "apb_base_addr"  : "0x80000000",
        "stt_base_addr"  : "0x40000000",
        "size_type"      : {
            "REG": 64,
            "LUT": 64,
            "STT": 128
        },
        "module": [
            "BE_SYS", "BE_BIU",
            "DEC", "BLC", "aaa", "qwe", "AESTAT",
            "AWBSTAT", "AWB", "BDRC", "DM", "GAMMA",
            "RGBDITHER", "abc", "SHP", "Y2RCSC", "CDS", "YUVDITHER","YUVDITHER"
        ],

        "nums": [
            1,2,3,4,5,6
        ],

        "tests" : [{"test1": 100, "test2": 200, "test3": 300 } ,
                   {"test1": 400, "test2": 500, "test3": 600 }],

        "repeat":{
                "a1" : {"test1": 100, "test2": 200, "test3": 300 } ,
                "b1" : {"test4": 400, "test5": 500, "test6": 600 }
        }
    },
    "PE2" : 0
}

python脚本:

json解析代码:

#################################################################################
# Company: 
# Engineer: 

# Create Date: 2022/7/25
# Project Name:
# Design Name:
# Module Name: json_parse
# Description:
#      parse json file
# Dependencies:
#
# Record:
#  Revision     Date        Description
#    v0.1     2022/7/25     parse json
# Additional Comments:
##################################################################################


import json

def is_addr(addr):
    return (addr.find("0x") == 0) and (addr[2:-1].isdigit())

def is_array(node):
    if ((node.find("{") != -1) and (node.find("}") != -1)):
        if ((node.find("[") != -1) and (node.find("]") != -1)
                and (node.find("}")   1 == node.find("["))):
            return True
        if ((node.find("(") != -1) and (node.find(")") != -1)
                and (node.find("}")   1 == node.find("["))):
            return True
    return False

def is_number(value):
    return value.isdigit()

def is_struct_array(node, member_list):
    if((is_array(node)) and (member_list[-1] != node)):
        return True
    return False

def is_number_array(node, member_list):
    if((is_array(node)) and (member_list[-1] == node)):
        return True
    return False

def load_json(fp):
    try:
        data = json.load(fp)
    except Exception as e:
        print("This is not a json file! %s" % e)
        return ""
    return data

def analyze_data(data, result, members):
    if isinstance(data, dict):
        for k, v in data.items():
            analyze_data(v, result   "->get{\"%s\"}" % str(k), members)
    elif isinstance(data, (list, tuple)):
        for i in range(len(data)):
            analyze_data(data[i], result   "[%s]" % i, members)
    else:
        members.append(result   "="   str(data))

def get_members(fp, members):
    data = load_json(fp)
    if data != "":
        analyze_data(data, "{\"json_config\"}", members)

def get_max_depth(members):
    max_depth = 0
    for i in members:
        max_depth = max(max_depth, len(i.split("->")) - 1)

    return max_depth

def get_member_lists(members_array):
    member_lists = []
    for member in members_array:
        member_list = member.split("->")
        member_lists.append(member_list)
    return member_lists

def get_node_name(node, format):
    node_name_first = node.find("{\"")   2
    node_name_end = node.find("\"}")
    node_name = node[node_name_first:node_name_end]
    if format == "array":
        if ((node.find("[") != -1
             and
             node.find("]") != -1)):
            index_1 = node.find("[")   1
            index_2 = node.find("]")
            node_name  = "["   node[index_1:index_2]   "]"
    return node_name

def get_array_index(node):
    index_left = node.find("[")   1
    index_right = node.find("]")
    array_index = node[index_left:index_right]
    return array_index


def check_value(value):
    if value.count(".") != 1:
        if value.isdigit():
            return "int"
        elif value.count("-") == 1 and value.startswith("-"):
            num = value.split("-")[-1]
            if num.isdigit():
                return "int"
            else:
                return check_bool(value)
        else:
            return check_bool(value)
    else:
        left = value.split(".")[0]
        right = value.split(".")[1]
        if right.isdigit():
            if left.isdigit():
                return "double"
            elif left.count("-") == 1 and left.startswith("-"):
                left_num = left.split("-")[-1]
                if left_num.isdigit():
                    return "double"
                else:
                    return check_bool(value)
            else:
                return check_bool(value)
        else:
            return check_bool(value)

def check_bool(value):
    if value.title() in ("True", "On"):
        return "bool"
    elif value.title() in ("False", "Off"):
        return "bool"
    elif is_addr(value):
        return "unsigned int"
    else:
        return "char *"

def get_type(node, member_list):
    if is_number_array(node, member_list):
        value = node.split("=")[-1]
        return "array "   check_value(value)

    if(node.find("=") != -1):
        value = node.split("=")[-1]
        return check_value(value)

    if is_struct_array(node, member_list):
        for i, temp in enumerate(member_list):
            if(temp == node):
                node_child = member_list[i 1]
                return "array "   "struct "   get_node_name(node, "")   "_s"

    return "struct "   get_node_name(node, "")   "_s"

def find_fathers(node_pre_names, node_name, node_father_names):
    node_pres = node_father_names.get(node_name, False)
    if (node_pres):
        for i in node_pres:
            if i== node_pre_names:
                return True
    return False



def get_node_info_list(member_lists):
    node_info_list = []
    node_father_names = {}
    row = len(member_lists)

    flag = 0  # json
    for i, member_list in enumerate(member_lists):
        for j, node in enumerate(member_list):

            node_info = {}
            node_name = get_node_name(node, "")
            node_pre_names = []
            node_pres = []
            if j == 0 and flag == 1:
                continue

            # root
            if j == 0:
                node_info["name"] = node_name
                child_names = []
                node_info["value"] = ""
                child_type = {}

                number = 0
                if node.find("[") != -1 and node.find("]") != -1:
                    index_l = node.find("[")
                    index_r = node.find("]")
                    last_node = member_lists[-1][0]
                    number = max(number, int(last_node[index_l   1: index_r]))

                for index in range(i, row):
                    if (len(member_lists[index]) <= j):
                        break
                    if (member_lists[index][j] != node):
                        break

                    node_child = member_lists[index][j   1]
                    child_name = get_node_name(node_child, "")
                    child_names.append(child_name)
                    child_type[child_name] = get_type(node_child, member_lists[index])

                child_names = list(set(child_names))

                node_info["child_name"] = child_names
                node_info["child_num"] = len(child_names)
                node_info["child_type"] = child_type
                node_info["self_type"] = "struct "   node_name   "_s"
                node_info["depth"] = j
                node_info["json_number"] = number
                node_info_list.append(node_info)
                flag = 1
                continue

            index = j - 1
            while (index >= 0):
                node_pre_name = get_node_name(member_list[index], "array")
                node_pre_names.append(node_pre_name)
                index -= 1

            if (j > 0
                    and
                (not find_fathers(node_pre_names, node_name, node_father_names))
                    ) :
                node_info["name"] = node_name
                node_info["father_name"] = node_pre_names
                node_pres.append(node_pre_names)
                node_father_names[node_name] = node_pres

                # leaf node (array)
                if (is_number_array(node, member_list)):
                    node_value_list = []
                    for index in range(i, row):
                        if (len(member_lists[index]) <= j):
                            break

                        if (get_node_name(member_lists[index][j], "") != node_name):
                            break
                        node_value_list.append(member_lists[index][j][member_lists[index][j].find("=")   1:])

                    node_info["value"] = node_value_list
                    for i in node_value_list:
                        node_info["self_type"] = "array "   check_value(i)
                        break

                    node_info["child_num"] = len(node_value_list)
                    node_info["depth"] = j
                    node_info_list.append(node_info)
                    continue

                # leaf node (value)
                if (node.find("=") != -1):
                    node_value = node[node.find("=")   1:]
                    node_info["value"] = node_value
                    node_info["self_type"] = get_type(node, member_list)
                    node_info["depth"] = j
                    node_info_list.append(node_info)

                    continue

                # struct array
                if (is_struct_array(node, member_list)):
                    child_names = []
                    node_info["value"] = ""
                    child_type = {}
                    arr_index = "0"

                    for index in range(i, row):
                        if (len(member_lists[index]) <= j):
                            break
                        if (get_node_name(member_lists[index][j], "") != node_name):
                            break

                        arr_index = get_array_index(member_lists[index][j])
                        node_child = member_lists[index][j   1]
                        child_name = get_node_name(node_child, "")
                        child_names.append(child_name)
                        child_type[child_name] = get_type(node_child, member_list)
                        node_info["self_type"] = "array "   "struct "   node_name   "_s"

                    child_names = list(set(child_names))
                    node_info["child_name"] = child_names
                    node_info["child_num"] = int(arr_index)   1
                    node_info["child_type"] = child_type
                    node_info["depth"] = j
                    node_info_list.append(node_info)

                    continue

                # dict json
                child_names = []
                node_info["value"] = ""
                child_type = {}

                for index in range(i, row):
                    if (len(member_lists[index]) <= j):
                        break
                    if (member_lists[index][j] != node):
                        break
                    node_child = member_lists[index][j   1]
                    child_name = get_node_name(node_child, "")
                    child_names.append(child_name)
                    child_type[child_name] = get_type(node_child, member_lists[index])

                child_names = list(set(child_names))
                node_info["child_name"] = child_names
                node_info["child_num"] = len(child_names)
                node_info["child_type"] = child_type
                node_info["self_type"] = "struct "   node_name   "_s"
                node_info["depth"] = j
                node_info_list.append(node_info)
    return node_info_list


def get_nodes_info_from_jsonFile(file_path):
    members_array = []
    with open(file_path, "r ") as fp:
        get_members(fp, members_array)
        max_depth = get_max_depth(members_array)
        member_lists = get_member_lists(members_array)
        node_info_list = get_node_info_list(member_lists)
        return (node_info_list, max_depth)

代码生成部分:

#################################################################################
# Company: 
# Engineer: 

# Create Date: 2022/7/25
# Project Name:
# Design Name:
# Module Name: gen_code
# Description:
#      gen header file and config file from json file
# Dependencies:
#
# Record:
#  Revision     Date        Description
#    v0.1     2022/7/25     File Created
# Additional Comments:
##################################################################################

from utils.json_parse import *

def get_nodeinfo_dict(node_info_list):
    node_info_dict = {}

    for i in node_info_list:
        data_list = []
        name = i["name"]
        if(node_info_dict.get(name)):
            data_list = node_info_dict.get(name)
        data_list.append(i)
        node_info_dict[name] = data_list
    return  node_info_dict

def gen_struct(node_info, node_info_dict, fp):
    node_name = node_info["name"]
    fp.write(
        '/* Define the struct %s_s */\n' %node_name  
        'struct %s_s\n' %node_name  
        '{\n'
    )
    child_names = node_info["child_name"]
    child_types = node_info["child_type"]
    for child_name in child_names:
        child_type = child_types[child_name]

        # if array
        if (child_type.find("array") != -1):

            # find same node
            index = 0
            for i, j in enumerate(node_info_dict[child_name]):
                if j["name"] == node_name \
                        and j["self_type"] == node_info["self_type"] \
                        and j["child_types"] == node_info["child_types"]:
                    index = i
            child_child_num = node_info_dict[child_name][index]["child_num"]

            child_name  = "["   str(child_child_num)   "]"   ";"
            child_type = child_type.lstrip("array ")
            fp.write(
                '\t%s\t' % child_type.ljust(20)  
                child_name.ljust(30)
                  ' /* '.ljust(5)   child_name.rsplit(";")[0].ljust(15)   ' */\n'
            )
            continue

        child_name  = ";"
        fp.write(
            '\t%s\t' % child_type.ljust(20)  
            child_name.ljust(30)
              ' /* '.ljust(5)   child_name.rsplit(";")[0].ljust(15)    ' */\n'
        )
    fp.write(
        '}; \n\n'
    )

def get_depth_list(node_info_list, max_depth):
    depth_list = [[] for x in range(max_depth)]
    for node_info in node_info_list:
        depth = node_info["depth"]
        depth_list[depth-1].append(node_info)

    return depth_list

def is_same_father(node1, node2):
    if(node1["father_name"] == node2["father_name"]):
        return True
    return False

# not same node but same name and type
def is_same_name_and_type(gened_nodes, node):
    node_name = node["name"]
    processed = gened_nodes.get(node_name, False)
    if(not processed):
        if(not is_same_father(processed, node)
                and
            processed["self_type"] == node["self_type"]):
            return True
    return False

def is_same_struct(gened_nodes, node):
    node_name = node["name"]
    processed = gened_nodes.get(node_name)
    if (processed != None):
        processed = gened_nodes.get(node_name)
        if processed["child_type"] == node["child_type"]:
            return True

    return False

def get_father_str(node_info):
    if(node_info["value"] != ""):
        fathers = list(reversed(node_info["father_name"]))
        name = node_info["name"]

        ret = ""
        for val in fathers:
            ret  = val   "."

        # array
        if (node_info["self_type"].find("array") != -1):
            temp_name = ""
            for val in fathers:
                if(val.find("[") != -1 and val.find("]") != -1):
                    index_left = val.find("[")
                    index_right = val.find("]")
                    val = val[:index_left]   val[index_left 1:index_right]
                temp_name  = val   "_"
            temp_name  = name


            if(node_info["self_type"].find("*") != -1):
                temp = node_info["self_type"].lstrip("array ")   temp_name
            else:
                temp = node_info["self_type"].lstrip("array ")   " "   temp_name
            child_num = node_info["child_num"]
            temp  = "["   str(child_num)   "]"   " = "   "{"
            value_list = node_info["value"]

            for i, j in enumerate(value_list):
                if (i == len(value_list) - 1):
                    if (check_value(value_list[0]) != "char *"):
                        temp  = j
                    else:
                        temp  = "\""   j   "\""
                    continue
                if (check_value(value_list[0]) != "char *"):
                    temp  = j   ", "
                else:
                    temp  = "\""   j   "\""  ", "
            temp  = "};\n\t"

            ret  = name
            ret = temp   "memcpy("   temp_name   ", "   ret   ", sizeof("   temp_name   "));"
            return ret

        # not array
        val = node_info["value"]
        if (check_value(val) != "char *"):
            if(val == "True"):
                val = "true"
            if(val == "False"):
                val = "false"
        else:
            val = "\""   val   "\""
        ret  = name   " = "   val  ";"
        return ret
    return

def define_struct(node_info_dict, fp):
    node_info_config = node_info_dict["json_config"][0]
    if (node_info_config["json_number"] != 0):
        json_number = node_info_config["json_number"]
        fp.write("\t%s %s[%s];\n" % (node_info_config["self_type"],
                                     node_info_config["name"],
                                     str(json_number   1)))
    else:
        fp.write("\t%s %s;\n" % (node_info_config["self_type"], node_info_config["name"]))

def generate_struct_h(gened_nodes, node_info_list, node_info_dict, fp):
    fp.write("#ifndef __JSON_CONFIG_H\n")
    fp.write("#define __JSON_CONFIG_H\n")
    fp.write("#include <stdio.h>\n")
    fp.write("#include <stdlib.h>\n")
    fp.write("#include <string.h>\n\n")

    for node_info in node_info_list:
        node_name = node_info["name"]
        if node_info["value"] == "":
            # not generated
            if not is_same_struct(gened_nodes, node_info):
                gen_struct(node_info, node_info_dict, fp)
                gened_nodes[node_name] = node_info

    node_info_config = node_info_dict["json_config"][0]
    if (node_info_config["json_number"] != 0):
        fp.write("%s *config_init(void);\n" %node_info_config["self_type"])
    else:
        fp.write("%s config_init(void);\n" %node_info_config["self_type"])

    fp.write("#endif")

def generate_struct_init(node_info_dict, node_info_list, fp):
    node_info_config = node_info_dict["json_config"][0]
    fp.write("#include \"json_config.h\" \n\n")  # TODO
    if (node_info_config["json_number"] != 0):
        fp.write("%s *config_init(void)\n" %node_info_config["self_type"])
    else:
        fp.write("%s config_init(void)\n" %node_info_config["self_type"])

    fp.write("{\n")

    # define struct
    define_struct(node_info_dict, fp)

    for node_info in node_info_list:
        ret = get_father_str(node_info)
        if ret == None:
            continue
        fp.write("\t"   ret   "\n")

    fp.write("\treturn %s;\n" %node_info_config["name"])

    fp.write("}\n")

def generate_test(node_info_dict, test_path):
    with open(test_path, "w") as fp:
        fp.write("//******************************************************************************\n\
// Copyright     :  Copyright (C) 2022, NIOd.\n\
// File name     :  json_test.c \n\
// Author        :  yoshi.shao   \n\
// Version       :  1.0         \n\
// Date          :  2022-07-25    \n\
// Description   :  test  \n\
// History       :         \n\
//******************************************************************************\n\n")

        fp.write("#include \"json_config.h\"\n\n")
        fp.write("int main(void)\n{\n")
        node_info_config = node_info_dict["json_config"][0]

        if (node_info_config["json_number"] != 0):
            fp.write("\t%s *%s = " % (node_info_config["self_type"], node_info_config["name"]))
        else:
            fp.write("\t%s %s = " % (node_info_config["self_type"], node_info_config["name"]))

        fp.write("config_init();\n")
        fp.write("\treturn 0;\n")
        fp.write("}\n")

def generate_all(json_path, file_path, init_path, test_path):
    (node_info_list, max_depth) = get_nodes_info_from_jsonFile(json_path)

    node_info_dict = get_nodeinfo_dict(node_info_list)
    node_info_list = list(reversed(node_info_list))

    gened_nodes = {}

    # generate struct.h
    with open(file_path, "w") as fp:
        fp.write("//****************************************************************************** \n\
// Copyright     :  Copyright (C) 2022, NIOd.\n\
// File name     :  json_config.h      \n\
// Author        :  yoshi.shao        \n\
// Version       :  1.0  \n\
// Date          :  2022-07-25     \n\
// Description   :  Define all struct   \n\
// History       :          \n\
//******************************************************************************\n\n")
        generate_struct_h(gened_nodes, node_info_list, node_info_dict, fp)
    with open(init_path, "w") as fp:
        fp.write("//******************************************************************************\n\
// Copyright     :  Copyright (C) 2022, NIOd.\n\
// File name     :  json_config.c \n\
// Author        :  yoshi.shao   \n\
// Version       :  1.0         \n\
// Date          :  2022-07-25    \n\
// Description   :  init json struct  \n\
// History       :         \n\
//******************************************************************************\n\n")
        generate_struct_init(node_info_dict, node_info_list, fp)

    generate_test(node_info_dict, test_path)

以上就是Python实现将json文件生成C语言的结构体的脚本分享的详细内容,更多关于Python json文件生成C语言结构体的资料请关注Devmax其它相关文章!

Python实现将json文件生成C语言的结构体的脚本分享的更多相关文章

  1. XCode 3.2 Ruby和Python模板

    在xcode3.2下,我的ObjectiveCPython/Ruby项目仍然可以打开更新和编译,但是你无法创建新项目.鉴于xcode3.2中缺少ruby和python的所有痕迹(即创建项目并添加新的ruby/python文件),是否有一种简单的方法可以再次安装模板?我发现了一些关于将它们复制到某个文件夹的信息,但我似乎无法让它工作,我怀疑文件夹的位置已经改变为3.2.解决方法3.2中的应用程序模板

  2. 开始使用 swift 的 c语言 库

    为了手头上的一个项目,我需要使用CommonCrypto库中的HMAC函数.虽然苹果在swift中已经提供了许多系统库,但是CommonCrypto不在其中.庆幸的是,要使用这个库并不怎么费事,只需要做一点额外的工作.开始访问库在使用库之前,我们需要通知Swift编译器.要完成这个过程,我们有两种方式.它们都能在示例工程中正常运行,但是你应该根据你代码的用途来选择具体的方式.好消息是,你随便使用那

  3. Swift教程10-运算符与C语言的不同

    =,==这些运算符和其他语言的类似,是比较前后两个值是否相等,或者大小关系比较字符串内容是否相等,使用==即可但是Swift新增了===恒等于,是针对于引用类型,如两个对象之间是否是同一个对象与之对应的是!运算符示例Swift新增的??

  4. Swift 体会

    前言Swift体会我不算是一个果粉,但是我很喜欢苹果的产品,甚至可以说是狂热。运行速度从苹果官方所给出的数据来看,Objective-C比Python快2.8倍,而Swift比Python快3.9倍,可见苹果在Swift上下了大量的功夫进行优化。开发环境Swift语言的开发环境是苹果公司提供的集成开发环境Xcode,可以用来开发iOS应用、iOS游戏、OSX窗体程序、OSX游戏、OSX命令行程序,读者可以直接从AppStore中搜索并下载。由于Swift是苹果的产品,所以目前只支持苹果的系统。

  5. [翻译]Swift编程语言——关于Swift

    Swift是一门用于iOS和OSX应用开发的新的编程语言,它以C和Objective-C语言为基础,但没有C语言的兼容性约束。Swift的酝酿花费了数年。Apple为了Swift改进了已有的编译器、调试器和框架的底层。对于Objective-C语言的开发者,Swift是那样的似曾相识。在这个基础之上,Swift引入了许多新的特性并且支持面向对象编程。Swift将现代编程语言的精华和苹果工程文化中的智慧结合在一起。所有这些使得Swift对于开发者和Apple都是一笔对未来可靠的投资。

  6. swift笔记-赋值运算符

    复杂些的运算例如逻辑与运算符&&,或让i值加1的便捷自增运算符++i等。Swift支持大部分标准C语言的运算符,且改进许多特性来减少常规编码错误。当然允许你使用Swift的溢出运算符来实现溢出。本章节只描述了Swift中的基本运算符,高级运算符包含了高级运算符,及如何自定义运算符,及如何进行自定义类型的运算符重载。三元运算符操作三个操作对象,和C语言一样,Swift只有一个三元运算符,就是三目运算符(a?

  7. Swift基本使用-函数和闭包(三)

    声明函数和其他脚本语言有相似的地方,比较明显的地方是声明函数的关键字swift也出现了Python中的组元,可以通过一个组元返回多个值。传递可变参数,函数以数组的形式获取参数swift中函数可以嵌套,被嵌套的函数可以访问外部函数的变量。可以通过函数的潜逃来重构过长或者太复杂的函数。

  8. runTime(二)

    我们前面已经讲过一篇runtime原理,现在这篇文章主要介绍的是runtime是什么以及怎么用!首先,第一个问题,1》runtime实现的机制是什么,怎么用,一般用于干嘛?在我们平时编写的OC代码中,程序运行过程时,其实最终都是转成了runtime的C语言代码,runtime算是OC的幕后工作者比如说,下面一个创建对象的方法中,举例:OC:第二个问题runtime用来干什么呢??..这是我们学习runtime必须知道的函数!

  9. Swift:基本概述

    在介绍Swift之前,先说一段小插曲。Swift中文被翻译为“雨燕”。swift语言是苹果2014年6月3日正式推出一门新的的语言。),大家也许会困惑了,我不是在介绍Swift的使用吗?更容易让很多初学者愿意往Swift方面发展。并且它尽可能的保持方法名类名与objective-c中的一致,这也使得一些长期从事objective-c开发的程序员,很方便的转向Swift的开发。

  10. Swift学习笔记九——整型Int在Swift中表示的最大值最小值问题

    我们在学习C语言的时候,总是会去记忆一些数值,如int能表示的最大值最小值,long型能表示的最大值最小值。来到Swift中就比较简单了,直接用代码就可以看到类型所能表示的最值。。如图所示,Int8表示占一个字节,Int16表示占两个字节,以此类推。妈妈再也不用担心我记忆这些麻烦的数据了。

随机推荐

  1. 10 个Python中Pip的使用技巧分享

    众所周知,pip 可以安装、更新、卸载 Python 的第三方库,非常方便。本文小编为大家总结了Python中Pip的使用技巧,需要的可以参考一下

  2. python数学建模之三大模型与十大常用算法详情

    这篇文章主要介绍了python数学建模之三大模型与十大常用算法详情,文章围绕主题展开详细的内容介绍,具有一定的参考价值,感想取得小伙伴可以参考一下

  3. Python爬取奶茶店数据分析哪家最好喝以及性价比

    这篇文章主要介绍了用Python告诉你奶茶哪家最好喝性价比最高,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习吧

  4. 使用pyinstaller打包.exe文件的详细教程

    PyInstaller是一个跨平台的Python应用打包工具,能够把 Python 脚本及其所在的 Python 解释器打包成可执行文件,下面这篇文章主要给大家介绍了关于使用pyinstaller打包.exe文件的相关资料,需要的朋友可以参考下

  5. 基于Python实现射击小游戏的制作

    这篇文章主要介绍了如何利用Python制作一个自己专属的第一人称射击小游戏,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起动手试一试

  6. Python list append方法之给列表追加元素

    这篇文章主要介绍了Python list append方法如何给列表追加元素,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

  7. Pytest+Request+Allure+Jenkins实现接口自动化

    这篇文章介绍了Pytest+Request+Allure+Jenkins实现接口自动化的方法,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

  8. 利用python实现简单的情感分析实例教程

    商品评论挖掘、电影推荐、股市预测……情感分析大有用武之地,下面这篇文章主要给大家介绍了关于利用python实现简单的情感分析的相关资料,文中通过示例代码介绍的非常详细,需要的朋友可以参考下

  9. 利用Python上传日志并监控告警的方法详解

    这篇文章将详细为大家介绍如何通过阿里云日志服务搭建一套通过Python上传日志、配置日志告警的监控服务,感兴趣的小伙伴可以了解一下

  10. Pycharm中运行程序在Python console中执行,不是直接Run问题

    这篇文章主要介绍了Pycharm中运行程序在Python console中执行,不是直接Run问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

返回
顶部