Image

S

Sheldon

Hi,

Does anyone know how to read an array back into python after writing
it to a .dat file using tostring()?

My method using Image results in a valueerror: data is not enough...

x = open('file.dat')

array = x.read()

print array : results in unreadle garble while

im = Image.fromstring('I', (81,81),array)
gives the valueError: data not enough...

The tutorial on Image leaves a lot to be desired.

Any help or new ideas would be welcomed!

thanks,
Sheldon
 
F

Fredrik Lundh

Sheldon said:
im = Image.fromstring('I', (81,81),array)
gives the valueError: data not enough...

The tutorial on Image leaves a lot to be desired.

the same can be said about your ability to cut and paste: the error message
is "not enough image data" and means exactly what it says.

(in other words, the "array" variable contains less than 81*81*4 bytes)

are you running this on Windows? if so, you need to specify that the file
contains binary data when you open it:

f = open(filename, "wb") # open for writing
f = open(filename, "rb") # open for reading

see

http://docs.python.org/lib/built-in-funcs.html#l2h-25

for more details.

</F>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,294
Messages
2,571,511
Members
48,216
Latest member
DarrelLho

Latest Threads

Top