Re: Read long int from binary file
From: Enrico Morelli (enrico_morelli_at_yahoo.com)
Date: 10/15/03
- Next message: Stephen Horne: "Re: AI and cognitive psychology rant (getting more and more OT - tell me if I should shut up)"
- Previous message: cezar: "Re: Installer for BDB 4.1.25/BDBXML 1.1.0"
- In reply to: Alex Martelli: "Re: Read long int from binary file"
- Next in thread: Alex Martelli: "Re: Read long int from binary file"
- Reply: Alex Martelli: "Re: Read long int from binary file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 15 Oct 2003 11:40:01 +0200
On Wed, 15 Oct 2003 08:06:56 +0000, Alex Martelli wrote:
> Enrico Morelli wrote:
> ...
>> I do know the format (in advance).
>> I have some binary files coming from SGI boxes and other from Linux boxes.
>> These files contains 32 bit long integer data that I need to read and
>> display in some graphic format.
>> In some cases I have to reverse the byte order in other not.
>>
>> I'm unable to read these files and put the data in some array.
>> I tried to use f.read(4), but I have 4 numbers not one.
>
>
> import array
>
> x1 = array('l')
> f1 = file('file_ok.dat', 'rb')
> x1.fromfile(f1)
> f1.close()
>
> x2 = array('l')
> f2 = file('file_toswap.dat', 'rb')
> x2.fromfile(f2)
> x2.byteswap()
> f2.close()
>
>
> Alex
Thanks Alex!!!
A question, the fromfile syntax wants the n items to read.
x1.fromfile(f1,1) read exactly one 32 bit long integer?
Enrico
PS. Sei sempre 'r mejo!!
- Next message: Stephen Horne: "Re: AI and cognitive psychology rant (getting more and more OT - tell me if I should shut up)"
- Previous message: cezar: "Re: Installer for BDB 4.1.25/BDBXML 1.1.0"
- In reply to: Alex Martelli: "Re: Read long int from binary file"
- Next in thread: Alex Martelli: "Re: Read long int from binary file"
- Reply: Alex Martelli: "Re: Read long int from binary file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|