Read long int from binary file
Alex Martelli
aleax at aleax.it
Wed Oct 15 06:03:28 EDT 2003
Enrico Morelli wrote:
...
>> x1 = array('l')
>> f1 = file('file_ok.dat', 'rb')
>> x1.fromfile(f1)
...
> Thanks Alex!!!
Prego!-)
> A question, the fromfile syntax wants the n items to read.
Yes, sorry.
> x1.fromfile(f1,1) read exactly one 32 bit long integer?
Yes. x1.fromfile(f1,999) reads UP TO 999 long integers -- will
probably raise EOFError by finding less than 999 there, so use:
try: x1.fromfile(f1, 999)
except EOFError: pass
Also remember fromfile APPENDS to whatever was already in the
array x, so make sure x is empty before x.fromfile if needed.
> Enrico
>
> PS. Sei sempre 'r mejo!!
Troppo'bbono dotto`...;-)
Alex
More information about the Python-list
mailing list