Newbie lost(new info)

Angelo Secchi secchi at sssup.it
Thu Feb 26 04:16:57 EST 2004


John and Anthon thanks for your help.
If I did it correctly this is the outcome of the code you asked me to
try:

>from binascii import hexlify
>inf = file('foo','rb')
>data = inf.read(1970) # 1970 is the exact length of the line
>for i in range(4):   
>     index = i * 32
>     print hexlify(data[index: index+32])


3131313131313131312030313032323230313033343130323238353332303031
3220202020203032323835333230303132303030303031303030303030314338
3930303030303120203939333531302030313130303030312020313220313335
313030313032323230313033343133343146ee3bb40000000000000000465de3



>from binascii import hexlify
>inf = file('foo','rb')
>data = inf.read(1970)
>for i in range(223):
>     index = i * 4 + 113
>     print hexlify(data[index: index + 4])


46ee3bb4	(I know that this should be 15612852)
00000000	(I know that this should be 0)
00000000	(I know that this should be 0)
465de39a	(I know that this should be 6153114)
00000000	(I know that this should be 0)
00000000	(I know that this should be 0)
...


John just to understand what you said, if the file is in IBM propietary
binary format (EBCDIC ?) I cannot convert it in ASCII using Python?

Thanks again
Angelo







On Wed, 25 Feb 2004 20:18:47 -0500
"John Roth" <newsgroups at jhrothjr.com> wrote:

> 
> "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
> >
> >
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list


--
========================================================
 Angelo Secchi                     PGP Key ID:EA280337
========================================================
  Current Position:
  Graduate Fellow Scuola Superiore S.Anna
  Piazza Martiri della Liberta' 33, Pisa, 56127 Italy
  ph.: +39 050 883365
  email: secchi at sssup.it	www.sssup.it/~secchi/
========================================================




More information about the Python-list mailing list