Help me with this!!!

Paul McGuire ptmcg at austin.rr.com
Thu Feb 1 08:57:27 EST 2007


On Feb 1, 4:21 am, "TOXiC" <Gatling... at gmail.com> wrote:
> Hi all, I've this code:
>
>     regex = re.compile(r"(?si)(\x8B\xF0\x85\xF6)(?P<contents>.*)
> (\xC6\x44\x24)",re.IGNORECASE)
>     file = open(fileName, "rb")
>     for line in file:
>           if (match):
>               print line
>     file.close()
>
> It search a text inside that hex value.
> It works perfecly on a txt file but if I open a binary file (.exe,.bin
> ecc...) with the same value it wont work, why?
> Please help!

Where do you assign the value of 'match'?  Perhaps you are missing a
line such as "match=regex.match(line)" or "match=regex.search(line)"?
Perhaps this is why Peter Otten says that this code can't possibly be
the code that works for text files?

What is the significance of "for line in file" when file is opened in
binary mode?  Are EOLs properly interpreted in binary mode?  ('file'
is not the best variable name, by the way, as it masks Python's built-
in file.  How about "file_", or "inputfile", or "fileToBeSearched"?)

-- Paul




More information about the Python-list mailing list