Data interaction method and storage medium using python and c language

CN123011200APending Publication Date: 2026-10-30HEFEI JUNZHENG TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510565639.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-30
Publication Date
2026-10-30

AI Technical Summary

Technical Problem

[0004]1.数据格式不直观:现有技术中,C语言的fwrite函数直接将内存中的数据以二进制形式写入文件,生成的.dat硬盘文件的内容对于人类来说是不可读的

Benefits of technology

[0042]本发明通过C语言fwrite函数和Python struct模块,实现了C语言和Python之间的跨语言数据交互。该方法简单,具有以下优点:

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123011200A_ABST
    Figure CN123011200A_ABST
Patent Text Reader

Abstract

The application provides a data interaction method and storage medium realized by using python and C language, comprising the following steps: S1, defining a structure; S2, initializing a structure variable; S3, creating a binary dat file; S4, defining a format string; S5, calculating the size of the file; S6, reading the dat file; and S7, restoring the data of the dat file. The application realizes cross-language data interaction between C language and Python through the C language fwrite function and the Python struct module. The method has the following advantages: high efficiency: directly operating binary data, avoiding the overhead of text parsing, and improving the efficiency of data interaction; accuracy: through accurate format string definition, ensuring the accuracy of data parsing; flexibility: can adapt to various complex data structures and meet the needs of different application scenarios.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of cross-language data interaction technology, and specifically relates to data interaction methods and storage media implemented using Python and C languages. Background Technology

[0002] In existing technologies, data interaction between different programming languages ​​is a common problem in software development. C, with its efficiency and flexibility, is widely used in system programming and embedded development, while Python, with its simplicity and rich libraries, shines in fields such as data analysis and machine learning. How to efficiently and accurately transfer and parse data between C and Python has become an important research direction.

[0003] In other words, the existing technology has the following drawbacks:

[0004] 1. Unintuitive data format: In existing technology, the fwrite function in C language directly writes data in memory to a file in binary form, and the contents of the generated .dat hard disk file are unreadable to humans.

[0005] 2. Cross-language compatibility issues: Although Python's `struct` module can parse binary files generated by C, different programming languages ​​may have differences in data type definitions and memory layouts. This can lead to data type mismatches or parsing errors during cross-language parsing.

[0006] 3. Sensitivity to data structure changes: If the definition of a structure in C language changes (such as adding, deleting, or modifying member variables), the parsing code on the Python side also needs to be adjusted accordingly. Otherwise, the data will not be parsed correctly.

[0007] In addition, the technical terms in this field include:

[0008] 1. Serialization is the process of converting data structures or objects into a format that is easy to store or transmit. Serialized data can be saved to files, stored in databases, or transmitted over a network.

[0009] 2. Deserialization is the process of converting serialized data back into its original data structure or object. Deserialization allows programs to restore data from its stored format for further processing or use.

[0010] 3. Memory data. This refers to data temporarily stored in memory (RAM) during computer operation. Memory data has the following characteristics:

[0011] Temporary: Memory data will be lost when the computer is powered off or the program ends.

[0012] High-speed read and write: The memory read and write speed is very fast, which can meet the needs of programs for fast data access during runtime.

[0013] Volatility: Memory data is volatile, meaning that the data will be lost when the power is turned off.

[0014] 4. Hard disk files. These refer to data stored on a hard disk drive (HDD or SSD). Hard disk data has the following characteristics:

[0015] Persistence: Hard drive data remains even when the computer is powered off or the program ends, thus possessing persistence. Large capacity storage: Hard drives can store large amounts of data and are typically used for long-term storage of files, programs, and system data.

[0016] Slower read and write speeds: Compared to memory, hard drives have slower read and write speeds, but with technological advancements, SSD read and write speeds have significantly improved. Summary of the Invention

[0017] To address the aforementioned problems, the purpose of this application is to implement a cross-language data interaction method based on Python and C languages. This includes:

[0018] 1. Addressing the issue of unintuitive data format: In existing technologies, the C language's `fwrite` function directly writes data from memory to a file in binary form, resulting in an unreadable `.dat` file. This necessitates additional tools or code to parse the file content during debugging or data inspection. This invention, however, utilizes Python's `struct` module to directly convert binary data into readable Python data structures, facilitating debugging and subsequent processing.

[0019] 2. Addressing cross-language compatibility issues: Although Python's `struct` module can parse binary files generated by C, different programming languages ​​may have differences in data type definitions and memory layouts. This can lead to data type mismatches or parsing errors during cross-language parsing. This invention ensures data type matching between C and Python through precise format string definitions, improving cross-language compatibility.

[0020] 3. Sensitivity to Data Structure Changes: If the structure definition in C language changes (such as adding, deleting, or modifying member variables), the parsing code on the Python side also needs to be adjusted accordingly. Otherwise, data cannot be parsed correctly. This invention, through explicit format string definitions, allows changes to the data structure to be easily adjusted on the Python side, improving flexibility.

[0021] Specifically, this invention provides a data interaction method using Python and C languages, which enables cross-language data interaction and includes the following steps:

[0022] S1, Define the structure: Define the data structure in C language, including ddr_alloc_cl_t, rt_cl_is0os0_t and sim_info_t;

[0023] S2, Initialize structure variables: Initialize and assign values ​​to the member variables of the structure;

[0024] S3, Create a binary .dat file: Use the C language's fwrite function to write the initialized structure data into the .dat file in binary form;

[0025] S4, Define the format string: Define the format string corresponding to the structure in Python, and concatenate multiple format strings into a complete format string;

[0026] S5, Calculate file size: Based on the complete format string, use Python's struct.calcsize method to calculate the theoretical size of the .dat file;

[0027] S6, Read .dat file: Reads the contents of a .dat file in binary mode;

[0028] S7, Restore dat file data: Parse binary data using the struct.unpack method and restore the original structure data based on the format string.

[0029] The rules for generating the format string in step S4 are as follows:

[0030] Map the types of member variables in a C language structure to Python format characters;

[0031] The format strings of each part are concatenated in the order of the structure to form a complete parsing rule.

[0032] The restored data in step S7 includes:

[0033] Based on the length of the format string, determine the index range of each structure in the parsing result list; extract the corresponding data by index and output it in the original structure form.

[0034] The method further includes:

[0035] In C, use fopen to create a .dat file in binary write mode;

[0036] In Python, you can open a .dat file in binary read mode using the `open` command.

[0037] The method supports cross-platform data interaction and ensures parsing correctness across different systems by explicitly specifying the byte order.

[0038] The method avoids text parsing overhead by directly manipulating binary data, making it suitable for large-scale data processing scenarios and improving data interaction efficiency.

[0039] The method is suitable for high-performance data interaction between C and Python in embedded systems and large-scale data processing scenarios.

[0040] It also relates to a computer-readable storage medium including processor-executable instructions that, when run by the processor, perform any of the methods described above.

[0041] Therefore, this solution has the following advantages:

[0042] This invention achieves cross-language data interaction between C and Python using the C language's `fwrite` function and the Python `struct` module. This method is simple and has the following advantages:

[0043] High efficiency: Direct manipulation of binary data avoids the overhead of text parsing and improves the efficiency of data interaction.

[0044] Accuracy: Precise format string definitions ensure the accuracy of data parsing.

[0045] Flexibility: It can adapt to various complex data structures and meet the needs of different application scenarios. Attached Figure Description

[0046] The accompanying drawings, which are provided to further illustrate the invention and form part of this application, are not intended to limit the scope of the invention.

[0047] Figure 1 This is a flowchart illustrating the method described in this application.

[0048] Figure 2 This is a schematic diagram of the main code implementation of step S1 in this application.

[0049] Figure 3 This is a schematic diagram of the main code implementation of step S2 in the method of this application.

[0050] Figure 4 This is a schematic diagram of the main code implementation of step S3 in this application.

[0051] Figure 5 This is a schematic diagram of the main code implementation of step S4 in this application.

[0052] Figure 6 This is a schematic diagram of the main code implementation of step S5 in the method of this application.

[0053] Figure 7 This is a schematic diagram of the main code implementation of step S6 in the method of this application.

[0054] Figure 8 This is a schematic diagram of the main code implementation of step S7 in the method of this application.

[0055] Figure 9 This is a schematic diagram illustrating the process of creating data.dat in C language in a specific embodiment.

[0056] Figure 10 This is a schematic diagram of the reading method used in a specific embodiment.

[0057] Figure 11 This is a schematic diagram of the reading results in a specific embodiment. Detailed Implementation

[0058] To better understand the technical content and advantages of the present invention, the present invention will now be described in further detail with reference to the accompanying drawings.

[0059] This invention provides a cross-language data interaction method and storage medium based on Python and C languages, which achieves the following:

[0060] Cross-language compatibility: Data is transmitted directly through binary files, avoiding the conversion overhead of intermediate formats such as JSON / XML;

[0061] Highly efficient parsing: Python's struct module parses directly byte by byte, outperforming text processing; Flexible extensibility: Format strings can be dynamically adjusted to adapt to changes in different structures;

[0062] Cross-platform support: Explicitly specify byte order (e.g., "<" little endian, ">" big endian) to ensure correct parsing across different systems.

[0063] The method, such as Figure 1 As shown, it includes:

[0064] S1, define the structure:

[0065] Define the required data structures in C (such as ddr_alloc_cl_t, rt_cl_is0os0_t, sim_info_t, etc.), and specify the data types and order of each member variable.

[0066] like Figure 2The image shows a code example for this section, including: creating a structure definition: a C language structure definition; further including:

[0067] 1) Structure definition stage:

[0068] 1.1) ddr_alloc_cl_t:

[0069] Member ofdata_stt;

[0070] Members bs_stt, w_stt, reg_stt, rt_stt, etc.

[0071] 1.2) rt_cl_is0os0_t:

[0072] Members if_dma_chaddr and of_dma_chaddr;

[0073] Member tl_y_inc; etc.

[0074] Member or_waddr[2];

[0075] 1.3) sim_info_t:

[0076] Member xtr_top_line;

[0077] Member rdnm_vld

[100] ; etc.

[0078] 2) Variable declaration phase:

[0079] rt (of type rt_cl_is0os0_t) and sim_info (of type sim_info_t);

[0080] The variable is dma_data.

[0081] S2, Initialize the structure variables:

[0082] Initialize the defined structure variables by assigning specific values ​​to each member to ensure data integrity and correctness.

[0083] like Figure 3 The image shows a code example for this section, including: initializing the structure (init_structs represents the initialization assignment of structure members): C language initialization of the structure:

[0084] Function call:

[0085] The program calls the init_structs() function and passes the addresses of four structure variables as parameters: &ddr_alloc: a pointer to the ddr_alloc structure.

[0086] &rt: A pointer to the rt structure.

[0087] &sim_info: A pointer to the sim_info structure.

[0088] &dma_data: A pointer to a dma_data structure.

[0089] Parameter passing:

[0090] By passing by address (pointer), functions can directly access and modify the contents of these structures, rather than operating on copies.

[0091] Initialization operations:

[0092] Inside the init_structs() function, execution depends on the specific implementation.

[0093] S3, create a binary .dat file:

[0094] Use the C language's `fwrite` function to write the initialized structure data to a `.dat` file in binary format. During writing, the structure elements must be written sequentially according to their definition to ensure consistent data layout.

[0095] like Figure 4 The image shows a code example for this section, including: creating a .dat file using the C language's fwrite function; and saving the structure data to the disk file data.dat using the C language's fwrite function.

[0096] 1) Open the file

[0097] Use the fopen function to open the file named "data.dat" in binary write mode ("wb");

[0098] Assign the returned file pointer to the variable fp;

[0099] If the file fails to open, fp will be NULL (error handling is not shown in the code);

[0100] 2) Write the first structure data

[0101] Use the fwrite function to write the ddr_alloc structure to a file;

[0102] Parameter description:

[0103] &ddr_alloc: The memory address of the structure;

[0104] 1: The number of elements to be written;

[0105] sizeof(ddr_alloc_t): Size of each element (of type ddr_alloc_t); fp: Pointer to the target file;

[0106] 3) Write the data into the second structure.

[0107] Use the fwrite function to write the rt structure to a file;

[0108] Parameter description:

[0109] &rt: The memory address of the structure;

[0110] 1: The number of elements to be written;

[0111] sizeof(rt_cl_is0os0_t): The size of each element;

[0112] fp: Pointer to the target file;

[0113] 4) Write the data into the third structure.

[0114] Use the fwrite function to write the sim_info structure to a file;

[0115] Parameter description:

[0116] &sim_info: The memory address of the structure;

[0117] 1: The number of elements to be written;

[0118] sizeof(sim_info_t): The size of each element;

[0119] fp: Pointer to the target file;

[0120] 5) Write the fourth structure data.

[0121] Use the fwrite function to write the dma_data structure to a file;

[0122] Parameter description:

[0123] &dma_data: The memory address of the structure;

[0124] 1: The number of elements to be written;

[0125] sizeof(dma_data): The size of each element;

[0126] fp: Pointer to the target file;

[0127] 6) Close the file

[0128] Use the fclose function to close previously opened files;

[0129] Ensure all buffered data is written to disk and file resources are released.

[0130] S4, define the format string:

[0131] In Python, format strings are defined based on the member types of C language structs (e.g., "i" represents int32, "I" represents uint32, etc.), and the format strings of multiple structs are concatenated into a complete parsing rule. The rule for generating the format string is as follows:

[0132] Map the types of member variables in a C language structure to Python format characters;

[0133] The format strings of each part are concatenated in the order of the structure to form a complete parsing rule.

[0134] like Figure 5 The image shows a code example for this section, including: defining the format string in Python; defining the string used for parsing in Python, and concatenating the parsing rules of the three structures and one array into one:

[0135] 1) First, four string variables are defined to represent the parsing rules for different structures and arrays: sim_info_t_format is assigned the value "9i100i" and is used to parse the sim_info_t structure;

[0136] The ddr_alloc_cl_t_format is assigned the value "4I5I4i6i" for parsing the ddr_alloc_cl_t structure;

[0137] The rt_cl_is0os0_t_format is assigned the value "7i15i216i614i412i" and is used to parse the rt_cl_is0os0_t structure;

[0138] The dma_data_format is assigned the value "143I" for parsing the dma_data array;

[0139] 2) Then, through string concatenation, these four parsing rules are merged into a complete parsing rule string:

[0140] Use the + operator to connect sim_info_t_format, ddr_alloc_cl_t_format, rt_cl_is0os0_t_format and dma_data_format in sequence;

[0141] The concatenation result is assigned to the variable s_format;

[0142] 3) The final s_format is a combined format string, which will contain, in the following order: first, the parsing rules of sim_info_t;

[0143] Then there are the parsing rules for ddr_alloc_cl_t;

[0144] Next are the parsing rules for rt_cl_is0os0_t;

[0145] Finally, there are the parsing rules for the dma_data array.

[0146] S5, Calculation file Size:

[0147] The theoretical size of the .dat file is calculated using Python's struct.calcsize method based on the concatenated format string, in order to verify file integrity and guide subsequent reading operations.

[0148] like Figure 6 The image shows a code example for this section, including: calculating the size of the file to be read and calculating the theoretical size of data.dat according to the rules.

[0149] Use the struct.calcsize() function to calculate the size of a data structure in memory in bytes for a specific format.

[0150] `s_format` is a format string that defines the layout of the data structure and the type of each field. This format string follows the format specifications of Python's `struct` module.

[0151] S6, Read .dat file:

[0152] Open the .dat file in binary mode ("rb"), read a data block of the specified size, and ensure that the number of bytes read matches the theoretically calculated size.

[0153] like Figure 7 The following is a code example for this section, including: 6. Opening and reading a file: Parsing binary data based on a format string. Using the `read` function to read the contents of the `data.dat` file and using the `unpack` method to format it:

[0154] 1) Open the file:

[0155] Open the file named "data.dat" in binary read mode ("rb");

[0156] Use the with statement to ensure that the file is automatically closed after file operations are completed;

[0157] Assign the file object to the variable f;

[0158] 2) Reading data:

[0159] Read binary data of a specified size from file object f;

[0160] The read data is stored in the variable data;

[0161] 3) Unpacked data:

[0162] Use the struct.unpack() function to parse binary data;

[0163] Parse the data according to the predefined format string s_format;

[0164] Convert the unpacked tuple into a list;

[0165] The result is stored in the variable unpacked_data.

[0166] This code flow completes the process of reading data of a specified size from a binary file and parsing it into a Python list according to a given structure format.

[0167] S7, restore .dat file data:

[0168] Use Python's struct.unpack method to parse binary data according to the format string and obtain the original data in list form;

[0169] Based on the length of the format string for each structure, the index range of the data list is divided, and the structure data defined in the C language is restored one by one, then output or further processed. That is, the restored data includes:

[0170] Based on the length of the format string, determine the index range of each structure in the parsing result list; extract the corresponding data by index and output it in the original structure form.

[0171] like Figure 8 The image shows a code example for this section, including: restoring the original data of 3 structs and 1 array based on the known data length. The code then restores and prints the data of the 3 structs and 1 array sequentially.

[0172] 1) Define the structure length:

[0173] Define the length of the sim_info_t structure as 109 (calculated from the number 9 + 100 in the format string "9i100i");

[0174] Define the length of the ddr_alloc_c1_t structure as 19 (4+5+4+6, corresponding to the sum of the numeric parts of the format string "4I5I4i6i");

[0175] Define the length of the rt_c1_is0os0_t structure as 31 (7+1+5+2+6+4+4+2);

[0176] Define the length of the dma_data array as 143;

[0177] 2) Calculate the index position:

[0178] sim0: Starting index is 0;

[0179] sim1: The ending index is sim0 + sim_info_t_len(109);

[0180] ddr0: The starting index is the same as sim1 (109);

[0181] ddr1: The end index is ddr0 + ddr_alloc_c1_t_len (109 + 19 = 128);

[0182] rt0: The starting index is the same as ddr1 (128);

[0183] rt1: The ending index is rt0 + rt_c1_is0os0_t_len (128 + 31 = 159);

[0184] dma0: The starting index is the same as rt1 (159);

[0185] dma1: The ending index is dma0 + dma_data_len (159 + 143 = 302);

[0186] 3) Data printing process:

[0187] Print the title "sim_info_t======", then iterate through and print the data in the unpacked_data range from sim0 to sim1.

[0188] Print the title "ddr_alloc_c1_t====", then iterate through and print the data in the unpacked_data range from ddr0 to ddr1.

[0189] Print the title "rt_c1_is0os0_t======", then iterate through and print the data in the unpacked_data range from rt0 to rt1.

[0190] Print the title "dma========", then iterate through and print the data in the unpacked_data range from index dma0 to dma1.

[0191] This code process sequentially reconstructs and prints the data contents of three structures and one array, with each part having a clear title label.

[0192] The method further includes:

[0193] In C, use fopen to create a .dat file in binary write mode;

[0194] In Python, you can open a .dat file in binary read mode using the `open` command.

[0195] The method supports cross-platform data interaction and ensures parsing correctness across different systems by explicitly specifying the byte order.

[0196] The method avoids text parsing overhead by directly manipulating binary data, making it suitable for large-scale data processing scenarios and improving data interaction efficiency.

[0197] The method is suitable for efficient transmission and parsing of large-scale data, and in particular, it is suitable for high-performance data interaction between C and Python, especially for embedded systems, large-scale data processing and other scenarios.

[0198] Here is a specific example: A file named data.dat was created using the C language, and then this method was used to read the contents stored in the data.dat file:

[0199] like Figure 9 The diagram illustrates the process of creating a data.dat file in C language, including:

[0200] 1) Header file:

[0201] stdio.h: Standard input / output

[0202] stdlib.h: Standard library functions

[0203] The macro LMF_GROUP_NUM is defined as 4.

[0204] 2) Structure definition:

[0205] The ddr_alloc_cl_t structure contains:

[0206] Multiple 32-bit unsigned integer start address fields (tfdata_stt array, ofdata_stt, bs_sttt, etc.)

[0207] Multiple 32-bit signed integer fields of different sizes (tfdata_size array, ofdata_size, bs_size, etc.)

[0208] An output row pixel size field oltne_px_size

[0209] 3) main function:

[0210] Create a variable named data of type ddr_alloc_cl_t

[0211] Initialize the values ​​of each field in the structure by opening the file "data.dat" in binary write mode.

[0212] Write the entire structure to a file

[0213] Close the file and return 0.

[0214] like Figure 10 The image shows the reading method used in this invention, which uses the Python struct module to parse binary data. This code snippet demonstrates how to use the Python struct module to parse binary file data, including:

[0215] 1) Main functions

[0216] A structure format string '41411IIIIIIIIIII' is defined.

[0217] Calculate the size of the structure.

[0218] Read binary data from file 'data.dat'

[0219] Use struct.unpack to parse data

[0220] The parsed data is assigned to different variables.

[0221] Print all parsed data

[0222] 2) Variable Description

[0223] ifdata_str: A list consisting of the first four unsigned integers

[0224] ofdata_str: The 5th unsigned integer

[0225] bs_sttt to rt_sttt: 6th-9th unsigned integers

[0226] ifdata_size: A list consisting of the 10th to 13th unsigned integers

[0227] ofdata_size to oline_px_size: the 14th to 19th unsigned integers.

[0228] like Figure 11 As shown, this is the result of the reading. The figure shows the output after running the Python script open_dat2.py.

[0229] As can be seen, this method correctly reads the information written to data.dat using C language. The original data.dat file is a binary file and cannot be read by humans, but the correct information was read using this method.

[0230] This application also relates to a computer-readable storage medium including processor-executable instructions that, when executed by the processor, perform any of the methods described above.

[0231] In summary, the present invention can achieve the following:

[0232] Cross-language data interaction: Enables efficient data interaction between C and Python languages, directly transferring and parsing data through binary files, avoiding the complexity and performance loss of intermediate conversions.

[0233] Direct use of data format: The C language's fwrite function can be used to write structure data directly to a .dat file. Python can then directly parse this binary data through the struct module without any additional format conversion.

[0234] Efficient parsing mechanism: Through precise format string definitions, Python's struct module can quickly and accurately parse binary files generated by C language, ensuring data integrity and availability.

[0235] Flexibility and scalability: This method can dynamically adjust the format string according to different data structures, adapting to various complex data types and structures.

[0236] Furthermore, the present invention includes:

[0237] Innovation of the technical solution: This invention provides a new cross-language data interaction method by combining C language and Python, which is innovative and practical.

[0238] Accuracy of data parsing: By precisely matching format strings, the correct parsing of binary data in different language environments is ensured, improving the reliability of data interaction.

[0239] Performance optimization: Direct manipulation of binary data avoids the overhead of text parsing, improves the efficiency of data interaction, and is suitable for large-scale data processing scenarios.

[0240] Cross-platform compatibility: By explicitly handling byte order, the correctness of data parsing across different byte order systems is ensured, enhancing the versatility of the method.

[0241] Dynamic adaptability: Python's dynamic features allow for flexible responses to changes in data structures, improving the adaptability and extensibility of methods.

[0242] This technical solution can be applied to all series of Ingenic chips and similar chips.

[0243] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, various modifications and variations can be made to the embodiments of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A data interaction method implemented using Python and C languages, characterized in that: The method enables cross-language data interaction, including the following steps: S1, Define the structure: Define the data structure in C language, including ddr_alloc_cl_t, rt_cl_is0os0_t and sim_info_t; S2, Initialize structure variables: Initialize and assign values ​​to the member variables of the structure; S3, Create a binary .dat file: Use the C language's fwrite function to write the initialized structure data into the .dat file in binary form; S4, Define the format string: Define the format string corresponding to the structure in Python, and concatenate multiple format strings into a complete format string; S5, Calculate file size: Based on the complete format string, use Python's struct.calcsize method to calculate the theoretical size of the .dat file; S6, Read .dat file: Reads the contents of a .dat file in binary mode; S7, Restore dat file data: Parse binary data using the struct.unpack method and restore the original structure data based on the format string.

2. The data interaction method using Python and C languages ​​according to claim 1, characterized in that, The rules for generating the format string in step S4 are as follows: Map the types of member variables in a C language structure to Python format characters; The format strings of each part are concatenated in the order of the structure to form a complete parsing rule.

3. The data interaction method using Python and C languages ​​according to claim 1, characterized in that, The restored data in step S7 includes: Based on the length of the format string, determine the index range of each structure in the parsing result list; extract the corresponding data by index and output it in the original structure form.

4. The data interaction method using Python and C languages ​​according to claim 1, characterized in that, The method further includes: In C, use fopen to create a .dat file in binary write mode; In Python, you can open a .dat file in binary read mode using the `open` command.

5. The data interaction method using Python and C languages ​​according to claim 1, characterized in that, The method supports cross-platform data interaction and ensures parsing correctness across different systems by explicitly specifying the byte order.

6. The data interaction method using Python and C languages ​​according to claim 1, characterized in that, The method avoids text parsing overhead by directly manipulating binary data, making it suitable for large-scale data processing scenarios and improving data interaction efficiency.

7. The data interaction method using Python and C languages ​​according to claim 6, characterized in that, The method is suitable for high-performance data interaction between C and Python in embedded systems and large-scale data processing scenarios.

8. A computer-readable storage medium, characterized in that, Includes processor-executable instructions that, when executed by the processor, perform any of the methods described in claims 1-7.