[cse491] [ctb at msu.edu: Re: __iter__]
C. Titus Brown
ctb at msu.edu
Mon Oct 19 18:51:04 PDT 2009
----- Forwarded message from "C. Titus Brown" <ctb at msu.edu> -----
Date: Mon, 19 Oct 2009 18:37:35 -0700
From: "C. Titus Brown" <ctb at msu.edu>
To: Phil Deschaine <deschai5 at gmail.com>
Subject: Re: __iter__
On Mon, Oct 19, 2009 at 09:33:55PM -0400, Phil Deschaine wrote:
> Can you explain why you define __iter__ (self) in lab 7?
It's all because of the required interface. The WSGI app interface is as
follows:
The server will call the app with
x = app(environ, start_request)
Then the server will retrieve content from the app by iterating over
the return value:
content = ''
for content_chunk in x:
content += content_chunk
All three examples in the revised lab 7 notes adhere to this interface.
In the class example, 'x' is an object of type WSGIApp; __iter__ is just
how you tell Python what to return when it is iterated over.
Another, simpler response is: that's what works, so use it ;)
cheers,
--titus
--
C. Titus Brown, ctb at msu.edu
----- End forwarded message -----
--
C. Titus Brown, ctb at msu.edu
More information about the cse491-fall-2009
mailing list