neutrino said the following on 1/20/2005 7:53 PM:
Greetings to the Python gurus,

I have a binary file and wish to see the "raw" content of it. So I open
it in binary mode, and read one byte at a time to a variable, which
will be of the string type. Now the problem is how to print the binary
format of that charater to the standard output. It seems a common task
but I just cannot find the appropriate method from the documentation.
Thanks a lot.

Not a guru, but I will try to help out :-)

how about this:
>>> import binhex
>>> binhex.binhex('C:/windows/system32/telnet.exe', 'C:/TEMP/telnet.hex')
>>>

Now this is what telnet.hex looks like:
(This file must be converted with BinHex 4.0)

:#R4PE'jPG#jPH'8!2j!)[EMAIL PROTECTED]"d!
!N#2J!!!!$Kqk$J#d#FdKZ!&-c5&8D'Pc)("[EMAIL PROTECTED]&ZEQpd)'*P)(*eEL"
TEL"[EMAIL PROTECTED]([EMAIL PROTECTED]&THS#Cj([EMAIL PROTECTED]&TIS'P
DAU!QH8HJceTHS%Yj'[EMAIL PROTECTED]"RP#S-TDAU!'[EMAIL PROTECTED]
DAU!!N""343!!6!%$!&VGE6d!N!MJ!!m"#`%(!!$!!!!!"J)!N!AQ[3!!!"!!!!$
3!*!&!3!3!!!!!J!!"3!"!!8!!3!%!*!)i!)!!!3!!&Hl!3!$!!#!!!!%!!!3!*!
%%!!!%!#3"K!!N!Z3!-%!!-J!N!5J!J"B1!#3'[!5!!!F!*!M8!)!!-`!N!33!!$
F!J#3'LjdCAKd!!!!rVm!!!!3!!!!`!!!!!3!N!iJ!!"J,Q4KG'%!!!"mb`%!!0!

(... Big Snip ...)


Or how about this?

>>> f = open('C:/windows/system32/telnet.exe', 'rb')
>>> fcontents = f.read()
>>> import binhex
>>> print binhex.binascii.hexlify(fcontents[0:10])
'4d5a9000030000000400'
>>>

Is this what you want???

Thanks,
--Kartic

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to