Reading a binary file in as hex

Terry Reedy tjreedy at udel.edu
Wed Oct 18 00:26:18 EDT 2000


> import string
> str = open("binoranydata","rb").read()
> hexStr=""
> for x in range(0, len(str)):
>      hexStr=hexStr+hex(ord(str[x]))+"\n"
> print hexStr

If  the file is very long, do not do this -- it is o(n*n) == slow.
As other suggested, make a list of  chunks and then join with nothing or
any separator you want.







More information about the Python-list mailing list