Writing an image

Michael Hudson mwh at python.net
Fri Nov 7 10:09:07 EST 2003


"Mr. Costington" <noahd at juno.no.spam.com> writes:

> Hi all, I was trying to hava a CGI script return an image, but it was coming
> back corrupted.  So I tried this simple non-CGI test and still get errors:
> 
> import sys
> image = open('pic.jpg','rb').read()
> sys.stdout.write(image)
> 
> When I run this like "python pic.py > pic2.jpg"
> The resulting pic2.jpg is not identical to the original.  I looked at it in
> a hex editor, and it seems to be identical with the original pic.jpg, except
> for several 0D (carraige return) characters inserted throughout the file.

sys.stdout is not usually a binary-mode file.

Cheers,
mwh

-- 
  It could be argued that since Suitespot is infinitely terrible,
  that anything else, by very definition of being anything else,
  is infinitely superior.                -- ".", alt.sysadmin.recovery




More information about the Python-list mailing list