Python 如何从该文件中提取数据?

Python 如何从该文件中提取数据?,python,regex,Python,Regex,我有一个包含以下内容的文本文件: Block 15, type A, key 05a3e664414a :00 00 00 00 00 00 ff 07 80 69 94 82 c8 cc 46 0a Block 14, type A, key 05a3e664414a :14 14 14 18 10 18 13 13 10 13 18 19 11 10 11 15 Block 13, type A, key 05a3e6644

我有一个包含以下内容的文本文件:

Block 15, type A, key 05a3e664414a :00  00  00  00  00  00  ff  07  80  69  94  82  c8  cc  46  0a  
Block 14, type A, key 05a3e664414a :14  14  14  18  10  18  13  13  10  13  18  19  11  10  11  15  
Block 13, type A, key 05a3e664414a :15  14  14  14  18  10  18  13  13  10  13  18  19  11  10  11  
Block 12, type A, key 05a3e664414a :07  05  04  04  04  08  00  08  03  03  10  13  18  19  11  10  
Block 11, type A, key 05a398f21b26 :00  00  00  00  00  00  ff  07  80  69  4c  36  e4  30  46  0a  
Block 10, type A, key 05a398f21b26 :08  00  07  05  04  07  04  08  00  08  13  13  10  13  18  18  
Block 09, type A, key 05a398f21b26 :05  08  00  07  05  06  04  04  08  00  18  13  13  10  13  18  
Block 08, type A, key 05a398f21b26 :11  15  18  10  17  15  14  14  14  18  10  18  13  13  10  13  
Block 07, type A, key 0577a23d1e96 :00  00  00  00  00  00  ff  07  80  69  2c  3c  7a  44  ee  0a  
Block 06, type A, key 0577a23d1e96 :03  10  11  15  18  10  17  15  14  14  14  18  10  18  13  07  
Block 05, type A, key 0577a23d1e96 :09  07  10  11  15  18  10  17  15  14  14  14  18  10  18  13  
Block 04, type A, key 0577a23d1e96 :18  19  11  10  11  15  18  10  17  15  14  14  14  18  10  18  
Block 03, type A, key a64ca2e58cc1 :00  00  00  00  00  00  ff  07  80  69  a6  4c  a2  e5  8c  c1  
Block 02, type A, key a64ca2e58cc1 :00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  
Block 01, type A, key a64ca2e58cc1 :70  60  62  67  7a  50  42  55  65  59  42  5c  15  14  14  14  
Block 00, type A, key a64ca2e58cc1 :c4  ed  60  47  0e  08  04  00  62  63  64  65  66  67  68  69 
我想编写一个python程序来提取密钥并返回它们,如下所示:

[[0xa6, 0x4c, 0xa2, 0xe5, 0x8c, 0xc1],
[0x05, 0x77, 0xa2, 0x3d, 0x1e, 0x96],
[0x05, 0xa3, 0x98, 0xf2, 0x1b, 0x26],
[0x05, 0xa3, 0xe6, 0x64, 0x41, 0x4a],]
这等于:

[[hex form of block 00 key],
[hex form of block 04 key],
[hex form of block 08 key],
[hex form of block 12 key]]

我该怎么做?我的意思是如何检测使用正则表达式的模式?

没有正则表达式也可以

s="Block 15, type A, key 05a3e664414a :00  00  00  00  00  00  ff  07  80  69  94  82"

key = s.split()[5] # gets the key = 05a3e664414a

print ["0x%s" % key[i:i+2] for i in range(0, len(key), 2)]

# output ['0x05', '0xa3', '0xe6', '0x64', '0x41', '0x4a']

0x从哪里来?那是一个十六进制数。。。我更好奇a6和4c等从何而来…@AvinashRaj我补充说我自己啊,我想我现在明白了这是一个大文本文件还是一个小文本文件,你想使用正则表达式吗?它可以不用正则表达式来完成,而且对初学者来说比我+1简单一点
s="Block 15, type A, key 05a3e664414a :00  00  00  00  00  00  ff  07  80  69  94  82"

key = s.split()[5] # gets the key = 05a3e664414a

print ["0x%s" % key[i:i+2] for i in range(0, len(key), 2)]

# output ['0x05', '0xa3', '0xe6', '0x64', '0x41', '0x4a']