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: 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On 6/20/2011 6:04 PM, Joel wrote: > On Jun 4, 2:27 pm, "TommyVee" 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