Newbie has question that's not exactly Python...

Chris Gonnerman chris.gonnerman at usa.net
Tue Apr 3 23:32:39 EDT 2001


----- Original Message ----- 
From: "Andrew Dalke" <dalke at acm.org>
Subject: Re: Newbie has question that's not exactly Python...


> Gary Walker:
> >Here's some actual code of mine that doesn't work:
> >
> >************************************
> >#!/usr/bin/python
> >
> >import StringIO, cgi, os, sys, string, Image
> >
> >im = Image.open('backgroundimage.gif')
> 
>                add--> , "rb" <-- here ^^
> to make it
> im = Image.open('backgroundimage.gif', "rb")
> 
> else it won't work on MS Windows or Macs.

>From the first line of Gary's script I assume that the platform
is Unixoid, probably Linux or BSD.
 
> ># here I'll be drawing all over my image...
> >
> ># Now I want to send it to a browser...
> >sfp = StringIO.StringIO()
> >im.save(sfp,'gif')
> >
> >print 'Content-Type: image/gif\r\n\r\n'
> 
> Replace this with
> 
> sys.stdout.write("Content-Type: image/gif\r\n\r\n")
> 
> because print adds its own "\n" after it prints
> the text.

Andrew has this right in general, but I must admit that I've
never had to include the \r characters.  Does the standard
require that?

Gary, what exactly DOES this script wind up doing?  What error messages,
bad behavior, etc. do you see?  Can you point me/us to a web link which
demonstrates it?






More information about the Python-list mailing list