I am writing a python script which looks at common computer files and examines them for similar bytes, words, double word\'s. Though I need/want to see the files in Hex, ande c
codecs.open(_file, "rb", "hex")
is trying to decode the file's contents as being hex, which is why it's failing on you.
Considering your other "word at a time" target (I assume you mean "computer word", i.e. 32 bits?), you'll be better off encapsulating the open file into a class of your own. E.g.:
class HexFile(object):
def __init__(self, fp, wordsize=4):
self.fp = fp
self.ws = wordsize
def __iter__(self):
while True:
data = self.fp.read(self.ws)
if not data: break
yield data.encode('hex')
plus whatever other utility methods you'd find helpful, of course.