[Tutor] Reading a "Raw "Image File

Alan Gauld alan.gauld at btinternet.com
Sun Apr 12 22:42:31 CEST 2009


"Wayne Watson" <sierra_mtnview at sbcglobal.net> wrote 

>     raw_image=raw_file.read()

> One more question, when I tried (no 'wb') read(size=307200), 
> why di read balk at size, syntactically.

It doesn't balk at the size syntactically it finds what it thinks is 
an End Of file character code in the data and stops reading. 
That's how text files are terminated and why you need to use 
rb to read non text data. 

Having read it as binary its then up to you to interpret the binary 
byte stream in whatever way you need, for example decoding 
it with the struct module or treating it as an image for PIL to 
manipulate or whatever.

HTH,


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/l2p/



More information about the Tutor mailing list