Right now I've got a mod_wsgi script that's structured like this..
def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'
    response_headers = [('Content-type', 'text/plain'),
                    ('Content-Length', str(len(output)))]
    start_response(status, response_headers)
    return [output]
I was wondering if anyone knows of a way to change this to operate on a yield basis instead of return, that way I can send the page as it's being generated and not only once it's complete, so the page loading can go faster for the user.
However, whenever I swap the output for a list and yield it in the application(), it throws an error:
TypeError: sequence of string values expected, value of type list found
                def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'
    response_headers = [('Content-type', 'text/plain'),
                    ('Content-Length', str(len(output)))]
    start_response(status, response_headers)
    yield output
"However, whenever I swap the output for a list and yield it in the application(), it throws an error:"
Well, don't yield the list. Yield each element instead:
for part in mylist:
    yield part
or if the list is the entire content, just:
return mylist
Because the list is already an iterator and can yield by itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With