Newbie lost(new info)
John Roth
newsgroups at jhrothjr.com
Wed Feb 25 20:18:47 EST 2004
"Anton Vredegoor" <anton at vredegoor.doge.nl> wrote in message
news:403d3b33$0$11500$3a628fcd at reader2.nntp.hccnet.nl...
> "John Roth" <newsgroups at jhrothjr.com> wrote:
>
> >For the rest of it, I'd like to see a *real* hex dump in mainframe
> >format. From what you've given us so far I'm not certain whether
> >the struct module can convert the data for you.
>
> Probably what John wants to see is the output of something like this:
>
> #one 'line' of data (since it's a binary file there is no real line
> #ending convention: a line is just a specific number of bytes long,
> #it's important to find out how many exactly)
>
> from binascii import hexlify
> inf = file('somefile','rb')
> data = inf.read(1005) #a 113 bytes string + 232 4 bytes floats
> L = map(hexlify,data)
> print L
>
> Anton
Thank you! I wasn't aware of that module. It looks like it
should do exactly what's needed.
Although this would probably do instead of the last 2 lines
(and excuse the fact that it's real ugly code, as well as
untested)
for i in range(4):
index = i * 32
print hexlify(data[index: index+32])
for i in range(232):
index = i * 4 + 113
print hexlify(data[index: index + 4])
John Roth
>
>
More information about the Python-list
mailing list