Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #7031

Re: Generator Frustration

References <4dea7932$0$28716$607ed4bc@cv.net> <4dead453$0$29996$c3e8da3$5496439d@news.astraweb.com> <95059eFuroU1@mid.individual.net>
Date 2011-06-04 22:06 -0400
Subject Re: Generator Frustration
From Jack Diederich <jackdied@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2462.1307239599.9059.python-list@python.org> (permalink)

Show all headers | View raw


On Sat, Jun 4, 2011 at 9:43 PM, Gregory Ewing
<greg.ewing@canterbury.ac.nz> wrote:
> Steven D'Aprano wrote:
>
>> A nice piece of syntax that has been proposed for Python is "yield from",
>> which will do the same thing, but you can't use that yet.

You can also patch the library to always return lists instead of generators.

def seriously_I_just_want_lists(func):
  def replacement(*args, **kwargs):
    return list(func(*args, **kwargs))
  return replacement

import otherlib
otherlib.somefunc = seriously_I_just_want_lists(otherlib.somefunc)

But I'd avoid it where you can.  While the idea of a list is simpler
than the idea of an iterable (and easier to get your head around)
iterables promise less and that makes them more flexible and easier to
composite.

-Jack

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Generator Frustration "TommyVee" <xxxxxxxx@xxxxxx.xxx> - 2011-06-04 14:27 -0400
  Re: Generator Frustration Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-05 00:56 +0000
    Re: Generator Frustration Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-06-05 13:43 +1200
      Re: Generator Frustration Jack Diederich <jackdied@gmail.com> - 2011-06-04 22:06 -0400
      Re: Generator Frustration "TommyVee" <xxxxxxxx@xxxxxx.xxx> - 2011-06-05 20:11 -0400
  Re: Generator Frustration Jan Decaluwe <jan@jandecaluwe.com> - 2011-06-05 11:52 +0200
  Re: Generator Frustration Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-06-06 11:07 +0200
    Re: Generator Frustration "TommyVee" <xxxxxxxx@xxxxxx.xxx> - 2011-06-07 20:41 -0400

csiph-web