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


Groups > comp.lang.python > #8053

Re: Generator Frustration

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'instance': 0.05; 'function,': 0.07; 'terry': 0.07; 'concurrency': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'pm,': 0.10; 'def': 0.12; 'wrote:': 0.14; 'expression).': 0.16; 'lambda': 0.16; 'reedy': 0.16; 'simulations.': 0.16; 'class,': 0.16; 'result,': 0.16; 'yield': 0.19; 'jan': 0.20; 'header:In-Reply-To:1': 0.21; '(or': 0.24; 'code': 0.24; 'function': 0.25; 'statement': 0.26; 'definition': 0.26; "i'm": 0.27; 'problem': 0.28; 'functions.': 0.29; 'class': 0.29; 'anyone': 0.32; 'header:X-Complaints-To:1': 0.32; 'to:addr:python-list': 0.33; 'actually': 0.33; 'header:User- Agent:1': 0.35; 'changes.': 0.35; 'using': 0.35; 'test': 0.35; 'several': 0.36; "who's": 0.37; 'put': 0.37; 'received:org': 0.38; 'run': 0.38; 'subject:: ': 0.38; 'some': 0.38; 'called': 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'note:': 0.63; 'here': 0.66; "'if": 0.84; 'generator,': 0.84; 'joel': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: Generator Frustration
Date Mon, 20 Jun 2011 21:42:40 -0400
References <4dea7932$0$28716$607ed4bc@cv.net> <08751bba-1216-4ee9-8a02-c14d21322213@a31g2000vbt.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host rain.gmane.org
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10
In-Reply-To <08751bba-1216-4ee9-8a02-c14d21322213@a31g2000vbt.googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.208.1308620570.1164.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 82.94.164.166
X-Trace 1308620570 news.xs4all.nl 49176 [::ffff:82.94.164.166]:58295
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:8053

Show key headers only | 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