【发布时间】:2021-04-28 11:34:20
【问题描述】:
我有 2 个以字节形式读取的文件,还有另一个硬编码的 64 字节数组,我需要稍后对其进行操作。
temp_list = []
open_file_to_list(file_name1, temp_list)
open_file_to_list(file_name2, temp_list)
for byte_i in harcoded_arr: #byte_i is really an int
temp_list.append(byte_i)
为了创建硬编码数组,我使用了 bytearray,但是当我对其进行迭代时,它会以整数而不是字节的形式进行迭代。
我想将字节数组作为字节追加到列表中。
harcoded_arr= bytearray(64)
harcoded_arr[61] = 1
harcoded_arr[62] = 1
harcoded_arr[63] = 1
如何使用 Python 3.8 将 bytearray 迭代为字节
【问题讨论】:
-
你想让
harcoded_arr[63] = 1成为bytearray(b'\x01')吗? -
@toRex 是的,那个也是。但我希望整个数组作为字节列表。添加到其他列表
标签: arrays python-3.x list