Re: Yield after the return in Python function.

2021-04-07 Thread Chris Angelico
On Wed, Apr 7, 2021 at 10:30 PM Stestagg wrote: > > > > On Wed, Apr 7, 2021 at 12:31 PM Chris Angelico wrote: >> >> >> I just realised that the whole eval/exec/namespace stuff is massive >> overkill. All you need is an object that is inconsistent in its >> boolification... >> > > Somewhat related

Re: Yield after the return in Python function.

2021-04-07 Thread Stestagg
On Wed, Apr 7, 2021 at 12:31 PM Chris Angelico wrote: > > I just realised that the whole eval/exec/namespace stuff is massive > overkill. All you need is an object that is inconsistent in its > boolification... > > Somewhat related: https://bugs.python.org/issue42899 Steve -- https://mail.pytho

Re: Yield after the return in Python function.

2021-04-07 Thread Chris Angelico
On Tue, Apr 6, 2021 at 12:40 PM Terry Reedy wrote: > > On 4/5/2021 3:32 PM, Chris Angelico wrote: > > > On Tue, Apr 6, 2021 at 5:14 AM Terry Reedy wrote: > >> Python *could* do the same for expresssions: load 'a' (in this case) > >> once into a register or stack slot and use that value consistent

Re: Yield after the return in Python function.

2021-04-05 Thread Terry Reedy
On 4/5/2021 3:32 PM, Chris Angelico wrote: On Tue, Apr 6, 2021 at 5:14 AM Terry Reedy wrote: Python *could* do the same for expresssions: load 'a' (in this case) once into a register or stack slot and use that value consistently throughout the expression. Replacing the eval with the following

Re: Yield after the return in Python function.

2021-04-05 Thread Dan Stromberg
On Mon, Apr 5, 2021 at 10:46 AM Terry Reedy wrote: > If there were a 'dead > (unreachable) code' exception, a reader or compiler would have to > analyze each use of 'yield' and decide whether it is reachable or not. > It's also subject to how hard the compiler feels like trying in any given rele

Re: Yield after the return in Python function.

2021-04-05 Thread Greg Ewing
On 6/04/21 4:02 am, Terry Reedy wrote: *Any* use of 'yield' in a function makes the function a generator function.  ...  If there were a 'dead (unreachable) code' exception, a reader or compiler would have to analyze each use of 'yield' and decide whether it is reachable or not. It would als

RE: Yield after the return in Python function.

2021-04-05 Thread Avi Gross via Python-list
--Original Message- From: Python-list On Behalf Of Terry Reedy Sent: Monday, April 5, 2021 3:01 PM To: python-list@python.org Subject: Re: Yield after the return in Python function. On 4/5/2021 1:53 PM, Chris Angelico wrote: > On Tue, Apr 6, 2021 at 3:46 AM Terry Reedy wrote: >> *While &#x

Re: Yield after the return in Python function.

2021-04-05 Thread Chris Angelico
On Tue, Apr 6, 2021 at 5:14 AM Terry Reedy wrote: > > On 4/5/2021 1:53 PM, Chris Angelico wrote: > > On Tue, Apr 6, 2021 at 3:46 AM Terry Reedy wrote: > >> *While 'a and not a' == False in logic, in Python it might raise > >> NameError. But that would still mean that it is never True, making > >

Re: Yield after the return in Python function.

2021-04-05 Thread Terry Reedy
On 4/5/2021 1:53 PM, Chris Angelico wrote: On Tue, Apr 6, 2021 at 3:46 AM Terry Reedy wrote: *While 'a and not a' == False in logic, in Python it might raise NameError. But that would still mean that it is never True, making 'yield 0' still unreachable. When I wrote that, I knew I might be m

Re: Yield after the return in Python function.

2021-04-05 Thread Chris Angelico
On Tue, Apr 6, 2021 at 3:46 AM Terry Reedy wrote: > *While 'a and not a' == False in logic, in Python it might raise > NameError. But that would still mean that it is never True, making > 'yield 0' still unreachable. > And even just the lookup can have side effects, if your code is pathologicall

Re: Yield after the return in Python function.

2021-04-05 Thread Terry Reedy
On 4/5/2021 8:25 AM, Bischoop wrote: The return suspends the function execution so how is it that in below example I got output: def doit(): return 0 yield 0 print(doit()) *Any* use of 'yield' in a function makes the function a generator function. This is a simple rule that

Re: Yield after the return in Python function.

2021-04-05 Thread Frank Millman
On 2021-04-05 2:25 PM, Bischoop wrote: The return suspends the function execution so how is it that in below example I got output: def doit(): return 0 yield 0 print(doit()) The 'yield' in the function makes the function a 'generator' function. 'Calling' a generator functio

Re: yield from () Was: Re: weirdness with list()

2021-03-12 Thread Thomas Jollans
On 03/03/2021 01:01, Cameron Simpson wrote: On 02Mar2021 15:06, Larry Martell wrote: I discovered something new (to me) yesterday. Was writing a unit test for generator function and I found that none of the function got executed at all until I iterated on the return value. Aye. Generators are

Re: yield from () Was: Re: weirdness with list()

2021-03-11 Thread Chris Angelico
On Fri, Mar 12, 2021 at 8:20 AM Serhiy Storchaka wrote: > > 01.03.21 23:59, Cameron Simpson пише: > > On 28Feb2021 23:47, Alan Gauld wrote: > >> On 28/02/2021 00:17, Cameron Simpson wrote: > >>> BUT... It also has a __iter__ value, which like any Box iterates over > >>> the subboxes. For MDAT tha

Re: yield from () Was: Re: weirdness with list()

2021-03-11 Thread Serhiy Storchaka
01.03.21 23:59, Cameron Simpson пише: > On 28Feb2021 23:47, Alan Gauld wrote: >> On 28/02/2021 00:17, Cameron Simpson wrote: >>> BUT... It also has a __iter__ value, which like any Box iterates over >>> the subboxes. For MDAT that is implemented like this: >>> >>> def __iter__(self): >>>

Re: yield from () Was: Re: weirdness with list()

2021-03-02 Thread Cameron Simpson
On 02Mar2021 15:06, Larry Martell wrote: >I discovered something new (to me) yesterday. Was writing a unit test >for generator function and I found that none of the function got >executed at all until I iterated on the return value. Aye. Generators are lazy - they don't run at all until you ask f

Re: yield from () Was: Re: weirdness with list()

2021-03-02 Thread Larry Martell
On Tue, Mar 2, 2021 at 2:16 PM Chris Angelico wrote: > > On Tue, Mar 2, 2021 at 5:51 AM Alan Gauld via Python-list > wrote: > > > > On 28/02/2021 00:17, Cameron Simpson wrote: > > > > > BUT... It also has a __iter__ value, which like any Box iterates over > > > the subboxes. For MDAT that is impl

Re: yield from () Was: Re: weirdness with list()

2021-03-02 Thread Marco Sulla
On Mon, 1 Mar 2021 at 19:51, Alan Gauld via Python-list wrote: > Sorry, a bit OT but I'm curious. I haven't seen > this before: > > yield from () > > What is it doing? > What do the () represent in this context? It's the empty tuple. -- https://mail.python.org/mailman/listinfo/python-list

Re: yield from () Was: Re: weirdness with list()

2021-03-02 Thread Chris Angelico
On Tue, Mar 2, 2021 at 5:51 AM Alan Gauld via Python-list wrote: > > On 28/02/2021 00:17, Cameron Simpson wrote: > > > BUT... It also has a __iter__ value, which like any Box iterates over > > the subboxes. For MDAT that is implemented like this: > > > > def __iter__(self): > > yield f

Re: yield from () Was: Re: weirdness with list()

2021-03-02 Thread Alan Gauld via Python-list
On 28/02/2021 23:47, Alan Gauld via Python-list wrote: > On 28/02/2021 00:17, Cameron Simpson wrote: > >> BUT... It also has a __iter__ value, which like any Box iterates over >> the subboxes. For MDAT that is implemented like this: >> >> def __iter__(self): >> yield from () > > Sorr

Re: yield from () Was: Re: weirdness with list()

2021-03-02 Thread Chris Angelico
On Wed, Mar 3, 2021 at 8:21 AM Dieter Maurer wrote: > > Alan Gauld wrote at 2021-2-28 23:47 +: > >yield from () > > "yield from iterator" is similar to "for i in iterator: yield i" (with > special handling when data/exceptions are injected into the generator). > > Thus, "yield from ()" does es

Re: yield from () Was: Re: weirdness with list()

2021-03-02 Thread Peter Otten
On 01/03/2021 00:47, Alan Gauld via Python-list wrote: On 28/02/2021 00:17, Cameron Simpson wrote: BUT... It also has a __iter__ value, which like any Box iterates over the subboxes. For MDAT that is implemented like this: def __iter__(self): yield from () Sorry, a bit OT but I

Re: yield from () Was: Re: weirdness with list()

2021-03-02 Thread Cameron Simpson
On 28Feb2021 23:47, Alan Gauld wrote: >On 28/02/2021 00:17, Cameron Simpson wrote: >> BUT... It also has a __iter__ value, which like any Box iterates over >> the subboxes. For MDAT that is implemented like this: >> >> def __iter__(self): >> yield from () > >Sorry, a bit OT but I'm cur

Re: yield from

2020-03-24 Thread Chris Angelico
On Wed, Mar 25, 2020 at 10:08 AM Dan Stromberg wrote: > > Some time ago, when I first heard about yield from, it wasn't faster than a > for loop yielding. > > Has that improved? It's not about speed. It's about correctness, and the way it delegates everything, not just "for x in iter: yield x". H

Re: yield in try/finally case

2016-03-03 Thread Oscar Benjamin
On 3 March 2016 at 15:12, Random832 wrote: > On Thu, Mar 3, 2016, at 08:47, Peter Otten wrote: >> This is because the last generator uf = upperfile(...) is not garbage- >> collected and wasn't explicitly closed either. > > But the program hasn't ended yet when you run your assertion. > > import sy

Re: yield in try/finally case

2016-03-03 Thread Peter Otten
Random832 wrote: > On Thu, Mar 3, 2016, at 08:47, Peter Otten wrote: >> This is because the last generator uf = upperfile(...) is not garbage- >> collected and wasn't explicitly closed either. > > But the program hasn't ended yet when you run your assertion. If your expectations are in line with

Re: yield in try/finally case

2016-03-03 Thread Steven D'Aprano
On Fri, 4 Mar 2016 02:00 am, Random832 wrote: > On Thu, Mar 3, 2016, at 06:52, 刘琦帆 wrote: >> I have just saw PEP 255, and it says that >> >> "A yield statement is not allowed in the try clause of a try/finally >> construct. The difficulty is that there's no guarantee the generator >> will ever b

Re: yield in try/finally case

2016-03-03 Thread Random832
On Thu, Mar 3, 2016, at 08:47, Peter Otten wrote: > This is because the last generator uf = upperfile(...) is not garbage- > collected and wasn't explicitly closed either. But the program hasn't ended yet when you run your assertion. import sys _open = open files = [] def myclose(self): pri

Re: yield in try/finally case

2016-03-03 Thread Random832
On Thu, Mar 3, 2016, at 06:52, 刘琦帆 wrote: > I have just saw PEP 255, and it says that > > "A yield statement is not allowed in the try clause of a try/finally > construct. The difficulty is that there's no guarantee the generator > will ever be resumed, hence no guarantee that the finally block

Re: yield in try/finally case

2016-03-03 Thread Peter Otten
刘琦帆 wrote: > 在 2016年3月3日星期四 UTC+8下午8:14:29,Oscar Benjamin写道: >> On 3 March 2016 at 11:52, 刘琦帆 wrote: >> > >> > "A yield statement is not allowed in the try clause of a try/finally >> > construct. The difficulty is that there's no guarantee the generator >> > will ever be resumed, hence no guaran

Re: yield in try/finally case

2016-03-03 Thread 刘琦帆
在 2016年3月3日星期四 UTC+8下午8:14:29,Oscar Benjamin写道: > On 3 March 2016 at 11:52, 刘琦帆 wrote: > > > > "A yield statement is not allowed in the try clause of a try/finally > > construct. The difficulty is that there's no guarantee the generator will > > ever be resumed, hence no guarantee that the fina

Re: yield in try/finally case

2016-03-03 Thread Oscar Benjamin
On 3 March 2016 at 11:52, 刘琦帆 wrote: > > "A yield statement is not allowed in the try clause of a try/finally > construct. The difficulty is that there's no guarantee the generator will > ever be resumed, hence no guarantee that the finally block will ever get > executed; that's too much a vio

Re: yield expression

2013-02-26 Thread Dave Angel
On 02/26/2013 01:44 PM, Colin J. Williams wrote: On 26/02/2013 12:07 PM, Vytas D. wrote: Hi, You are using "yield" incorrectly. "yield" works like return, but it can return more than once from the same function. Functions that "yield" produce a so called "generator" object. This generator objec

Re: yield expression

2013-02-26 Thread Colin J. Williams
On 26/02/2013 12:07 PM, Vytas D. wrote: Hi, You are using "yield" incorrectly. "yield" works like return, but it can return more than once from the same function. Functions that "yield" produce a so called "generator" object. This generator object gives you values every time you call it. The ge

Re: yield expression

2013-02-26 Thread Vytas D.
Hi, You are using "yield" incorrectly. "yield" works like return, but it can return more than once from the same function. Functions that "yield" produce a so called "generator" object. This generator object gives you values every time you call it. The generator works very interesting way. It sta

Re: yield expression

2013-02-26 Thread Dave Angel
On 02/26/2013 11:34 AM, Colin J. Williams wrote: On 24/02/2013 7:36 PM, Ziliang Chen wrote: Hi folks, When I am trying to understand "yield" expression in Python2.6, I did the following coding. I have difficulty understanding why "val" will be "None" ? What's happening under the hood? It seems t

Re: yield expression

2013-02-26 Thread Ian Kelly
On Tue, Feb 26, 2013 at 9:34 AM, Colin J. Williams wrote: > Perhaps it's becaoue (teild count) is a statement. Statements do not return > a value. yield is a bit of an odd duck in that it's both a statement and an expression. Compare: http://docs.python.org/3/reference/simple_stmts.html#the-yi

Re: yield expression

2013-02-26 Thread Colin J. Williams
On 24/02/2013 7:36 PM, Ziliang Chen wrote: Hi folks, When I am trying to understand "yield" expression in Python2.6, I did the following coding. I have difficulty understanding why "val" will be "None" ? What's happening under the hood? It seems to me very time the counter resumes to execute, it

Re: yield expression

2013-02-24 Thread Ziliang Chen
On Monday, February 25, 2013 8:51:28 AM UTC+8, Oscar Benjamin wrote: > On 25 February 2013 00:39, Ziliang Chen wrote: > > > Hi folks, > > > When I am trying to understand "yield" expression in Python2.6, I did the > > following coding. I have difficulty understanding why "val" will be "None" >

Re: yield expression

2013-02-24 Thread Oscar Benjamin
On 25 February 2013 00:39, Ziliang Chen wrote: > Hi folks, > When I am trying to understand "yield" expression in Python2.6, I did the > following coding. I have difficulty understanding why "val" will be "None" ? > What's happening under the hood? It seems to me very time the counter resumes >

Re: yield all entries of an iterable

2010-10-24 Thread Cameron Simpson
On 25Oct2010 01:37, Stefan Schwarzer wrote: | From the question and the code snippet the OP gave I assumed | he meant that there already was a sequence (i. e. linear | structure) to begin with. I suspected that was your interpretation. | By the way, I think a well-known example of what you | des

Re: yield all entries of an iterable

2010-10-24 Thread Stefan Schwarzer
Hi Cameron, On 2010-10-25 01:08, Cameron Simpson wrote: > On 24Oct2010 20:58, Stefan Schwarzer wrote: > | On 2010-10-21 00:27, Sebastian wrote: > | > Is there a simpler way to yield all elements of a sequence than this? > | > for x in xs: > | > yield x > | > | Can you give an example where y

Re: yield all entries of an iterable

2010-10-24 Thread Cameron Simpson
On 24Oct2010 20:58, Stefan Schwarzer wrote: | On 2010-10-21 00:27, Sebastian wrote: | > Is there a simpler way to yield all elements of a sequence than this? | > for x in xs: | > yield x | | Can you give an example where you would need this? Can't | you just iterate over the sequence? The us

Re: yield all entries of an iterable

2010-10-24 Thread Stefan Schwarzer
Hi Sebastian, On 2010-10-21 00:27, Sebastian wrote: > Is there a simpler way to yield all elements of a sequence than this? > for x in xs: > yield x Can you give an example where you would need this? Can't you just iterate over the sequence? If you really need an iterator, you can use `iter(s

Re: yield all entries of an iterable

2010-10-23 Thread Chris Rebert
On Wed, Oct 20, 2010 at 3:27 PM, Sebastian wrote: > Hi, > Is there a simpler way to yield all elements of a sequence than this? > for x in xs: >    yield x Not presently. There's a related PEP under discussion though: PEP 380: Syntax for Delegating to a Subgenerator http://www.python.org/dev/peps

Re: yield expression programmized-formal interpretation. (interpretation of yield expression.)

2008-04-21 Thread Gabriel Genellina
En Mon, 21 Apr 2008 15:03:05 -0300, <[EMAIL PROTECTED]> escribió: What if I say oath= yield or other= yield ? Does yield evaluate without parenthes? (Eth.) You can't use yield except in a generator function. From and the grammar definit

Re: yield keyword usage

2007-07-30 Thread Steve Holden
Ehsan wrote: > hi > coulde any one show me the usage of "yield" keyword specially in this > example: > > > """Fibonacci sequences using generators > > This program is part of "Dive Into Python", a free Python book for > experienced programmers. Visit http://diveintopython.org/ for the > latest

Re: yield keyword usage

2007-07-30 Thread [EMAIL PROTECTED]
On Jul 30, 4:40 pm, Erik Jones <[EMAIL PROTECTED]> wrote: > On Jul 30, 2007, at 4:13 PM, Ehsan wrote: > > > > > > > hi > > coulde any one show me the usage of "yield" keyword specially in this > > example: > > > """Fibonacci sequences using generators > > > This program is part of "Dive Into Pytho

Re: yield keyword usage

2007-07-30 Thread Erik Jones
On Jul 30, 2007, at 4:13 PM, Ehsan wrote: > hi > coulde any one show me the usage of "yield" keyword specially in this > example: > > > """Fibonacci sequences using generators > > This program is part of "Dive Into Python", a free Python book for > experienced programmers. Visit http://diveintop

Re: `yield` in a `try/finally` block, pre-Python 2.5

2007-06-04 Thread Adam Atlas
On Jun 4, 1:49 am, yuce <[EMAIL PROTECTED]> wrote: > I had the same problem, you can > see:http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/130004 > for a solution. > > Happy hacking, > > Yuce Thanks. I thought of doing something like that, but in my program, it's important that the order

Re: `yield` in a `try/finally` block, pre-Python 2.5

2007-06-03 Thread yuce
I had the same problem, you can see: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/130004 for a solution. Happy hacking, Yuce On Jun 4, 8:23 am, Adam Atlas <[EMAIL PROTECTED]> wrote: > I'm trying to emulate the Python 2.5 behaviour (PEP 342) of generator > functions where the `yield`

Re: yield, curry, mix-in, new.function, global, closure, .... what will work?

2007-04-16 Thread ecir . hana
On Apr 17, 3:51 am, [EMAIL PROTECTED] wrote: > I'm reading the docs now and I stumbled upon something: > section "15.3 threading -- Higher-level threading interface" mensions > a class "local", in which "... Thread-local data are data whose values > are thread specific. ..." > > Does it mean, I can

Re: yield, curry, mix-in, new.function, global, closure, .... what will work?

2007-04-16 Thread ecir . hana
I'm reading the docs now and I stumbled upon something: section "15.3 threading -- Higher-level threading interface" mensions a class "local", in which "... Thread-local data are data whose values are thread specific. ..." Does it mean, I can create global variables whose changing is thread- safe?

Re: yield, curry, mix-in, new.function, global, closure, .... what will work?

2007-04-16 Thread ecir . hana
On Apr 16, 5:36 pm, "Jason" <[EMAIL PROTECTED]> wrote: > On Apr 16, 7:28 am, [EMAIL PROTECTED] wrote: > > > > > On Apr 16, 3:05 am, Paul Rubin wrote: > > > > [EMAIL PROTECTED] writes: > > > > > Please, can you elaborate further, I'm not sure if I understood. > > > > Shoul

Re: yield, curry, mix-in, new.function, global, closure, .... what will work?

2007-04-16 Thread Jason
On Apr 16, 7:28 am, [EMAIL PROTECTED] wrote: > On Apr 16, 3:05 am, Paul Rubin wrote: > > > [EMAIL PROTECTED] writes: > > > > Please, can you elaborate further, I'm not sure if I understood. > > > Should I lock global variables i, j during the execution of run()? In > > >

Re: yield, curry, mix-in, new.function, global, closure, .... what will work?

2007-04-16 Thread ecir . hana
On Apr 16, 3:05 am, Paul Rubin wrote: > [EMAIL PROTECTED] writes: > > > Please, can you elaborate further, I'm not sure if I understood. > > Should I lock global variables i, j during the execution of run()? In > > that case I have to apologize, I showed rather simplified

Re: yield, curry, mix-in, new.function, global, closure, .... what will work?

2007-04-15 Thread Paul Rubin
[EMAIL PROTECTED] writes: > On Apr 15, 8:07 pm, Paul Rubin wrote: > > That is total madness. Just use a normal object or dictionary with a lock. > > Please, can you elaborate further, I'm not sure if I understood. > Should I lock global variables i, j during the executi

Re: yield, curry, mix-in, new.function, global, closure, .... what will work?

2007-04-15 Thread ecir . hana
On Apr 15, 8:07 pm, Paul Rubin wrote: > That is total madness. Just use a normal object or dictionary with a lock. Please, can you elaborate further, I'm not sure if I understood. Should I lock global variables i, j during the execution of run()? In that case I have to

Re: yield, curry, mix-in, new.function, global, closure, .... what will work?

2007-04-15 Thread Paul Rubin
[EMAIL PROTECTED] writes: > Let me explain: First, changer() is kind of templating language so it > should be written down in this form - however, it can change during > run-time as you like. Basically, it is just ordinary python code which > changes (should change) the local variables of another f

Re: Yield

2007-01-10 Thread Mikael Olofsson
I wrote: > The definition given there is "In mathematics , a > *prime number* (or a *prime*) is a natural number > that has exactly two (distinct) natural number > divisors ." The important part of the statement is > "exactly two...divisors", which rules out the number 1. Or should I say: T

Re: Yield

2007-01-10 Thread Mikael Olofsson
Mathias Panzenboeck wrote: > def primes(): > yield 1 > yield 2 > [snip rest of code] > Hmm... 1 is not a prime. See for instance http://en.wikipedia.org/wiki/Prime_number The definition given there is "In mathematics , a *prime number* (or a *prime*) is a natural number

Re: Yield

2007-01-09 Thread Mathias Panzenboeck
Fredrik Lundh schrieb: > Danny Colligan wrote: > >> Carsten mentioned that generators are more memory-efficient to use when >> dealing with large numbers of objects. Is this the main advantage of >> using generators? Also, in what other novel ways are generators used >> that are clearly superior

Re: Yield

2006-11-17 Thread Fredrik Lundh
Danny Colligan wrote: > Carsten mentioned that generators are more memory-efficient to use when > dealing with large numbers of objects. Is this the main advantage of > using generators? Also, in what other novel ways are generators used > that are clearly superior to alternatives? the main adv

Re: Yield

2006-11-16 Thread Tim Chase
>> I absoultely agree. Thanks for pointing me out to some real-world >> code. However, the function you pointed me to is not a generator >> (there is no yield statement... it just returns the entire list of >> primes). > > Oops, should have looked at the code more closely. Another example > wou

Re: Yield

2006-11-16 Thread Richard Brodie
"Danny Colligan" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I absoultely agree. Thanks for pointing me out to some real-world > code. However, the function you pointed me to is not a generator > (there is no yield statement... it just returns the entire list of > primes). O

Re: Yield

2006-11-16 Thread Carsten Haese
On Thu, 2006-11-16 at 08:09 -0800, Danny Colligan wrote: > > The more trivial the example, the harder it is to see the advantage. > > I absoultely agree. Thanks for pointing me out to some real-world > code. However, the function you pointed me to is not a generator > (there is no yield statemen

Re: Yield

2006-11-16 Thread Carsten Haese
On Thu, 2006-11-16 at 07:32 -0800, Danny Colligan wrote: > Carsten mentioned that generators are more memory-efficient to use when > dealing with large numbers of objects. Is this the main advantage of > using generators? Also, in what other novel ways are generators used > that are clearly superi

Re: Yield

2006-11-16 Thread Danny Colligan
> The more trivial the example, the harder it is to see the advantage. I absoultely agree. Thanks for pointing me out to some real-world code. However, the function you pointed me to is not a generator (there is no yield statement... it just returns the entire list of primes). A generator versi

Re: Yield

2006-11-16 Thread Richard Brodie
"Danny Colligan" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Now that we're on the subject, what are the advantages of using > generators over, say, list comprehensions or for loops? It seems to me > that virtually all (I won't say everything) the examples I've seen can > be do

Re: Yield

2006-11-16 Thread Danny Colligan
Now that we're on the subject, what are the advantages of using generators over, say, list comprehensions or for loops? It seems to me that virtually all (I won't say everything) the examples I've seen can be done just as easily without using generators. For example, Fredrik's initial example in

Re: Yield

2006-11-16 Thread John Machin
On 16/11/2006 7:00 PM, Fredrik Lundh wrote: > John Machin wrote: > >>> I would like to thanks Fredrik for his contribution to improve that. >> >> Call me crazy, but after an admittedly quick read, the version on the >> wiki seems to be about word for word with on the docs.python.org version. > >

Re: Yield

2006-11-16 Thread Fredrik Lundh
John Machin wrote: >> I would like to thanks Fredrik for his contribution to improve that. > > Call me crazy, but after an admittedly quick read, the version on the > wiki seems to be about word for word with on the docs.python.org version. maybe he was thinking about the article I posted, or t

Re: Yield

2006-11-15 Thread Fredrik Lundh
olive wrote: >> http://docs.python.org/ref/yield.html > > This is a perfect example that demonstrate how the actual python is bad > and most of the time useless (at least for me). there's a place for (relatively) formal reference documentation, but it's hardly ever the right place to learn why

Re: Yield

2006-11-15 Thread John Machin
On 16/11/2006 5:45 PM, olive wrote: > dwelch91 a écrit : >> http://docs.python.org/ref/yield.html > > This is a perfect example that demonstrate how the actual python is bad > and most of the time useless (at least for me). I think that you left the word "documentation" out after "python" :-) >

Re: Yield

2006-11-15 Thread olive
dwelch91 a écrit : > http://docs.python.org/ref/yield.html This is a perfect example that demonstrate how the actual python is bad and most of the time useless (at least for me). We really need mor example ! I would like to thanks Fredrik for his contribution to improve that. Olivier. -- htt

Re: Yield

2006-11-15 Thread dwelch91
Mateuszk87 wrote: > Hi. > > may someone explain "yield" function, please. how does it actually work > and when do you use it? > > thanks in forward > > mateusz > http://docs.python.org/ref/yield.html -- http://mail.python.org/mailman/listinfo/python-list

Re: Yield

2006-11-15 Thread John Henry
Thank you. This is very clear. I can see that this is useful in lots of situations. Fredrik Lundh wrote: > Mateuszk87 wrote: > > > may someone explain "yield" function, please. how does it actually work > > and when do you use it? > > it returns a value from a function without actually terminati

Re: Yield

2006-11-15 Thread Mateuszk87
thx for the quick answer. i ll have a look. -- http://mail.python.org/mailman/listinfo/python-list

Re: Yield

2006-11-15 Thread Carsten Haese
On Wed, 2006-11-15 at 09:13 -0800, Mateuszk87 wrote: > Hi. > > may someone explain "yield" function, please. how does it actually work > and when do you use it? [There is probably a much better explanation of this somewhere on the net already, but I feel like writing this out myself.] "yield" is

Re: Yield

2006-11-15 Thread Fredrik Lundh
Fredrik Lundh wrote: > reference information: also see: http://effbot.org/pyfaq/what-is-a-generator.htm -- http://mail.python.org/mailman/listinfo/python-list

Re: Yield

2006-11-15 Thread Fredrik Lundh
Mateuszk87 wrote: > may someone explain "yield" function, please. how does it actually work > and when do you use it? it returns a value from a function without actually terminating the function; when the function is resumed, it'll continue to execute after the yield. a function that contains

Re: Yield in a wrapper function

2005-11-18 Thread Bengt Richter
On 18 Nov 2005 05:08:39 -0800, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: >This works exactly as you would expect:: > > from time import sleep > def foo(on='ABC'): >for e in list(on): >sleep(1) >yield e > >When I run this on the command line It takes about 3 seconds to >com

Re: Yield in a wrapper function

2005-11-18 Thread Peter Otten
[EMAIL PROTECTED] wrote: > from time import sleep > def foo(on): > for e in list(on): Just for e in on: #... is better. The list() constructor defeats much of the laziness you gain by using a generator. > sleep(1) > yield e > > def wrapper(x): > if x < 0: >