On Feb 5, 3:08 pm, Jussi Salmela <[EMAIL PROTECTED]> wrote:
> metaperl kirjoitti:
>
> > For this program:
>
> > def reverse(data):
> >     for index in range(len(data)-1, -1, -1):
> >         yield data[index]
>
> > r = reverse("golf")
>
> > for char in r:
> >     print char
>
> > I'm wondering if the line:
>
> > r = reverse("golf")
>
> > "demands" the contents of the function reverse() all at once and if I
> > must write
>
> > for char in reverse("golf"):
> >     print char
>
> > if I want the results streamed instead of generated complely.
>
> > ** CONTEXT **
>
> > The simple example above is not what I am really doing. My real
> > program parses very large
> > data files using pyparsing. Pyparsing can generate incremental/yielded
> > results with no problem:
>
> >http://pyparsing.wikispaces.com/message/view/home/248539#248852
>
> > but because I believe in injection of control (pushing data around as
> > opposed to having
> > the target pull it), I get the parse and then inject it into the
> > generator:
>
> >             parse = parsing.parse(fp.read())
> >             txt = textgen.generate(self.storage.output, patent_key,
> > parse, f.basename(), debug=False)
>
> I don't know, I'm guessing:
>
>         ... r = reverse("golf")
>         ... type(r)
>         <type 'generator'>

very slick! thanks!

>         ... print r.next()
>         f
>
> So r is not the string 'flog', it is the generator producing it
>
> HTH,

It does!

> Jussi


-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to