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


Groups > comp.lang.python > #8053

Re: Generator Frustration

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Generator Frustration
Date 2011-06-20 21:42 -0400
References <4dea7932$0$28716$607ed4bc@cv.net> <08751bba-1216-4ee9-8a02-c14d21322213@a31g2000vbt.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.208.1308620570.1164.python-list@python.org> (permalink)

Show all headers | View raw


On 6/20/2011 6:04 PM, Joel wrote:
> On Jun 4, 2:27 pm, "TommyVee"<xxxxx...@xxxxxx.xxx>  wrote:
>> I'm using the SimPy package to run simulations. Anyone who's used this
>> package knows that the way it simulates process concurrency is through the
>> clever use of yield statements. Some of the code in my programs is very
>> complex and contains several repeating sequences of yield statements.  I
>> want to combine these sequences into common functions.  The problem of
>> course, is that once a yield gets put into a function, the function is now a
>> generator and its behavior changes.
...

> I actually found a reasonable answer to this, I think.  If one of the
> called functions contains a yield, that function is by definition a
> generator,

A nomenclature note: a function with yield is a 'generator function'. It 
is an instance of the 'function' class, same as for any other def 
statement (or lambda expression). It returns an instance of class 
'generator, as you note here

 > and will test as such with 'if type(result)==types.GeneratorType:'.

It is the result, and not the function, that is the generator (a type of 
iterator).

-- 
Terry Jan Reedy

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
  Re: Generator Frustration Joel <joel.welling@gmail.com> - 2011-06-20 15:04 -0700
    Re: Generator Frustration Terry Reedy <tjreedy@udel.edu> - 2011-06-20 21:42 -0400
      Re: Generator Frustration Joel <joel.welling@gmail.com> - 2011-06-20 20:03 -0700

csiph-web