Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用python定义字节数据矩阵_Python - Fatal编程技术网

使用python定义字节数据矩阵

使用python定义字节数据矩阵,python,Python,我将此数据保存在一个文件中: 00 00 1a 00 2f 48 00 00 88 9f 5d 04 00 00 00 00 10 04 a8 09 a0 00 c8 00 00 00 80 00 00 00 ff ff ff ff ff ff 00 25 9c 8f d5 bf 00 25 9c 8f d5 bf 40 7f 04 30 bc 61 02 00 00 00 64 00 21 04 00 05 54 49 52 41 44 01 04 82 84

我将此数据保存在一个文件中:

00 00 1a 00 2f 48 00 00  88 9f 5d 04 00 00 00 00   
10 04 a8 09 a0 00 c8 00  00 00 80 00 00 00 ff ff   
ff ff ff ff 00 25 9c 8f  d5 bf 00 25 9c 8f d5 bf   
40 7f 04 30 bc 61 02 00  00 00 64 00 21 04 00 05   
54 49 52 41 44 01 04 82  84 8b 96 03 01 0d 05 04   
00 01 00 00 20 01 00 2a  01 00 32 08 0c 12 18 24   
30 48 60 6c dd 18 00 50  f2 02 01 01 03 00 03 a4   
00 00 27 a4 00 00 42 43  5e 00 62 32 2f 00 dd 05   
00 50 f2 05 00 dd 0e 00  50 f2 04 10 4a 00 01 10   
10 44 00 01 02 dd 05 00  09 86 01 00 fe 66 cf c2
我想用python定义一个16列10行的矩阵,其中包含文件中的数据

请注意,例如,
ff
40
表示1个字节。

类似的内容

data = ''
with open ("in.txt", "r") as in_file:
    data = in_file.read().split(' ')
with open ("out.txt", "w") as out_file:
    position = 0
    for i in data:
        if 0 == (position % 16):
            out_file.write ("\r\n") #next line windows style.  for unix it should be \n
        out_file.write ("%s " % i)
        position += 1

文件是二进制还是十六进制/ascii(如果你用文本编辑器打开它,你会看到“00 01 a”还是一些“gibrish”?用文本编辑器我会看到00 01当我从终端(使用ubuntu)的python文件中删除它时,我有一个问题,我不清楚这个方法。问题是什么?将“in.txt”更改为输入文件,并将“out.txt”更改为“out.txt”到你的输出文件。我遗漏了什么吗?