获取之后的整数值:并从下一个值中减去它

时间:2017-04-14 11:28:18

标签: python-2.7

我有这样的文本文件,我需要从每行获取整数,如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]

1 个答案:

答案 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