About Splitting and Combining Records

Asked 2 months ago, Updated 2 months ago, 1 views

If you divide 10000 Byte records into 1000 Byte records, you can have 10 1000 Byte records, but the first record remains the same, and for the next nine records, you can delete 10 Byte from the beginning and make it 990 Byte
After that, I would like to combine the divided records. Is there a simple and good way?

Image
1234567890 | 1234567890 | 1234567890 Split
1234567890 | 234567890 | 234567890 Remove Top
1234567890234567890234567890 Combined

python python3

2022-09-30 14:18

1 Answers

How about the following?
Using the image in the questionnaire, we have combined 9 bytes, except for the first 1 byte of the 10 bytes record and the first 1 byte of the 10 bytes record.

If you change n to 1000 and m to 10, it will be the code for the original question.

data='1234567890123456789012345678901234567890'.encode('utf-8')#image data

n = 10# Number of bytes in the record (10 bytes)
m = 1 # Unnecessary first byte (1 byte)

# take out the first n bytes
ret = data [0:n]

# DATA ACQUISITION FROM OUTSIDE DATA
for i in range (n, len(data), n):
    ret=ret+data [i+m:i+n]

print(ret)# Output results to stdout


2022-09-30 14:18

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.