我有这样的文本文件,我需要从每行获取整数,如246012,并使用python从下一行的整数中减去它
[739:246012] PHYThrad: DSPMsgQ Received: msg type is[130] and SFNSF [14996] [SFN:937 SF:4]
[739:246050] START of MACThread:receved msg type[47]
[739:247021] PHYThrad: DSPMsgQ Received: msg type is[130] and SFNSF [14997] [SFN:937 SF:5]
[739:247059] START of MACThread:receved msg type[47]
[739:248013] PHYThrad: DSPMsgQ Received: msg type is[130] and SFNSF [14998] [SFN:937 SF:6]
[739:248053] START of MACThread:receved msg type[47]
答案 0 :(得分:0)
这应该可以解决问题:
with open('myfile.txt') as a:
a = a.readlines()
nums = [int(lines[lines.find(':')+1:lines.find(']')]) for lines in a]
result = [y - x for x, y in zip(nums, nums[1:])]
print result