File Uploads

Doug Helm dhelm at wcsoftware.com
Thu Mar 31 21:49:52 EST 2005


You're right, of course, and I do appreciate it.  I generally am calling
functions and returning strings and then printing the entire string.
For example:

def SomeFunc():
  lstrRetVal = ''
  lstrRetVal += 'Content-type: text/html\n\n'
  lstrRetVal += more HTML here...
  return lstrRetVal

Then, the calling code does:

print SomeFunc()

In this case, the extra new line character is appropriate.  Somehow, the
extra new line character slipped in on the print statement in my upload
sample code (I probably copied from a function that returns a string).  But
thanks just the same...

Just to be complete (so that no one comments about string concatenation
efficiency), in a real application I would generally use triple quotes for
HTML (or append to a list and then .join into a string at the end)...

Thanks to all for your help.

"Tim Roberts" <timr at probo.com> wrote in message
news:n3ok41l4u6k6sei2ndb03k26mhmh1sv43i at 4ax.com...
> "Doug Helm" <dhelm at wcsoftware.com> wrote:
>
> >Hey, Folks:
> >
> >I'm trying to write a very simple file upload CGI.  I'm on a Windows
server.
> >I *am* using the -u switch to start Python for CGIs, as follows:
> >
> >c:\python\python.exe -u %s %s
> >
> >I *do* have write permissions on the directory I'm trying to write to.
But,
> >when I click submit, it just hangs.  Any help would be greatly
appreciated.
> >Thanks.  Here's the code...
> >
> >Upload.py
> >
> >import cgi
> >
> >print "content-type: text/html\n\n"
>
> I see you got your problem solved, but you should know there is a problem
> with this line.  The print statement automatically adds an end-of-line, so
> this will actually end up producing TWO blank lines after the header.  You
> should use this:
>
>     print "Content-type: text/html\n"
> --
> - Tim Roberts, timr at probo.com
>   Providenza & Boekelheide, Inc.





More information about the Python-list mailing list