question about generators
Carl Banks
imbosol at vt.edu
Wed Aug 14 17:16:56 EDT 2002
Jonathan Hogg wrote:
> On 14/8/2002 16:38, in article yu993cthtpqr.fsf at europa.research.att.com,
> "Andrew Koenig" <ark at research.att.com> wrote:
>
>> I had a function along the following lines:
>>
>> def f():
>> if <condition>:
>> print <something>
>> else:
>> <do something>
>> f()
>> <do something else>
>>
>> and I wanted to turn it into a generator instead of having it
>> generate output directly. My first try was to change "print"
>> to "yield", and that failed horribly.
>
> I'm confused, the pattern you show above will only ever 'print <something>'
> once.
Not so fast! He could have two calls to f(), or the f() inside of a
loop. Omitted for simplicity, of course.
--
CARL BANKS
http://www.aerojockey.com
More information about the Python-list
mailing list