470,594 Members | 1,412 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,594 developers. It's quick & easy.

Image

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
Jul 18 '05 #1
1 2094
Sheldon wrote:
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>

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Pierre Tremblay | last post: by
3 posts views Thread by dave | last post: by
8 posts views Thread by Jef Driesen | last post: by
6 posts views Thread by QuasiChameleon | last post: by
15 posts views Thread by Anand Ganesh | last post: by
7 posts views Thread by lgbjr | last post: by
6 posts views Thread by comp.lang.php | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.