Newbie: EOF Error when making arrays .fromfile

Gerhard Häring gh_pythonlist at gmx.de
Tue Mar 19 17:32:34 EST 2002


Le 19/03/02 à 12:43, Matt Strange écrivit:
> hello all, i am very new to python and i'm using v2.2 on a Win98SE
> machine.  i needed to read in double-type data from an ASCII file
> (http://dnijaguar.tripod.com/planet0.dat).  this file contains 3000
> doubles separated by the tab("\t") value.  after reading information
> posted on this newsgroup, i decided that it would be best to first
> translate this ASCII data into a binary file using a c++ program
> (http://dnijaguar.tripod.com/atb.cpp).  then, i could read in this
> binary file (http://dnijaguar.tripod.com/bin0.dat) with the following
> lines of python:
> 
> >>> coord = array('d')
> >>> coord.fromfile(open("bin0.dat",'r'),3000)

Hmm. Works for me with your C++ and Python code. Perhaps (unlikely,
though) Python and your C++ compiler use different sizes for float. Btw.
these are 3003 values, if I see correctly.

If you don't need raw arrays and can use a list instead, this very
simple code does should do what you need:

d = map(float, open("planet0.dat").read().split())

Btw. Python doesn't have the distinction between 'float' and 'double'. A
Python float type is using a C double internally.

Gerhard
-- 
This sig powered by Python!
Außentemperatur in München: 6.7 °C      Wind: 2.3 m/s




More information about the Python-list mailing list