Newbie: EOF Error when making arrays .fromfile

Matt Strange dnijaguar at yahoo.com
Tue Mar 19 15:43:54 EST 2002


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)

however, there is a problem.  i recieve the error:
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
EOFError: not enough items in file

and when i type in "coord" from the >>> prompt to see what is stored
inside it, i see the values listed at the very end of this message;
i.e. the correct values, but definately not 3000 of them like i
wanted.  i would appreciate it if someone would tell me the reason i
am having this problem and the code necessary to fix it (with ASCII or
binary files). thank you very much for your help.

value of coord shown on command line:

array('d', [100000.0, 10000.0, -10000.0, 99995.0, 10001.0, -9998.0,
97469.199999
999997, 10493.200000000001, -8994.9799999999996, 94890.199999999997,
10969.0, -7
986.0299999999997, 92255.0, 11426.4, -6971.3000000000002,
89560.100000000006, 11
863.4, -5950.9799999999996, 86801.800000000003, 12277.799999999999,
-4925.369999
9999999, 83976.100000000006, 12666.6, -3894.8499999999999,
81078.399999999994, 1
3026.799999999999, -2859.9699999999998, 78103.5, 13354.6,
-1821.4400000000001, 7
5045.800000000003, 13645.5, -780.21400000000006, 71898.800000000003,
13894.20000
0000001, 262.42399999999998, 68655.199999999997, 14094.4, 1304.74,
65306.5999999
99999, 14238.299999999999, 2344.4000000000001, 61843.599999999999,
14316.2000000
00001, 3378.1500000000001, 58255.099999999999, 14316.299999999999,
4401.5, 54528
.599999999999, 14223.5, 5408.04, 50649.400000000001, 14018.5, 6388.46,
46600.699
999999997, 13676.4, 7328.8599999999997, 42363.400000000001,
13164.299999999999,
8207.8999999999996, 37917.5, 12439.6, 8991.7999999999993,
33244.199999999997, 11
447.799999999999, 9625.9500000000007, 28333.599999999999, 10126.6,
10022.7000000
00001, 23197.5, 8424.3799999999992, 10051.5, 17877.599999999999,
6340.1099999999
997, 9557.7600000000002, 12415.1, 3945.0, 8431.9799999999996,
6784.3100000000004
, 1310.78, 6655.5600000000004, 863.47900000000004,
-1607.8800000000001, 4227.600
0000000004, -5535.2299999999996, -5062.9700000000003, 1022.54,
-12557.1, -9702.5
100000000002, -3429.2600000000002, -19426.0, -17103.799999999999,
-10433.2999999
99999, -21219.700000000001, -28053.400000000001, -20689.5,
-16580.799999999999,
-38120.0, -30341.599999999999, -9804.4699999999993,
-46184.900000000001, -38337.
099999999999, -2476.6100000000001, -52974.699999999997])



More information about the Python-list mailing list