I have a block of code for searching a specific block of address and formatting the results in a certain way.
e.g, I have an input string "70D76320 BEG 701D135D 702D72FC END EAR0 00000000 0000000". I need to extract addresses between "BEG" and "END" which are "701D135D" and "702D72FC" in this case and format them in the following fashion:
[0]0x701D135D
[1]0x702D72FC
I wrote a script for that purpose:
import re
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--address', help='Parse the input addresses')
args = parser.parse_args()
addressInfo = args.address
filter = re.compile(r'(BEG )((\w{8})\s)+(END )')
btInfo = filter.search(addressInfo)
print ("\n")
addresses = btInfo.group().split()
for idx in range(len(addresses)):
if((addresses[idx] != 'BEG') and (addresses[idx] != 'END')):
print ("[%d]0x%s" %(idx-1, addresses[idx]))
When I review the code, it more like c/c++ code than python. Is there a better way the achieve the same result in the 'real python style'?