I'm new here, so please be gentle. I have posted my code at the following page:


In short, I need to read in my file, block by block, but have the re.finditer regular expression report the offsets relative to the beginning of the overall file, rather than relative to each freas 4096 byte block as it is read in.

Thanks for your help


Why don't you write

for each in wp_head:
        print "Word Perfect header %s found @ offset %d" % (
                             each.group(), total_data_read + each.start())


Another issue to consider is that a match could occur between 2 blocks, for example \xFF\x57 at the end of a 4096 bytes block and \x50\x43 at the beginning of the next block. Currently, your code won't find the match.

Thank you!

As usual, I had started looking at this long after my bedtime and had noted the total_data_read angle as my next line of attack to provide an accumalitive offset.I shall retire now otherwise I may well get my second wind and be up until the early hours!!

Kind Regards


This question has already been answered. Start a new discussion instead.