On Oct 21, 12:09 pm, Yingjie Lan wrote:
> Secondly, it would be nice to automatically revive it.
Sure, it's always nice when your expectation of a language feature
exactly matches with its capabilities.
When it doesn't, you suck it up and code around it.
Because at the very least it's a hell of
On Oct 21, 11:46 am, Yingjie Lan wrote:
> I am still not sure why should we enforce that
> a generator can not be reused after an explicit
> request to revive it?
No one is "enforcing" anything, you're simply resisting implementing
this yourself. Consider the following generator:
import rand
On Thursday, October 20, 2011 6:23:50 AM UTC-7, Yingjie Lan wrote:
> Hi,
>
> it seems a generator expression can be used only once:
>
> >>> g = (x*x for x in range(3))
> >>> for x in g: print x
> 0
> 1
> 4
> >>> for x in g: print x #nothing printed
> >>>
>
> Is there any way to revive g here?
R
On Fri, 21 Oct 2011 16:25:47 -0400, Terry Reedy wrote:
> Here is a class that creates a re-iterable from any callable, such as a
> generator function, that returns an iterator when called, + captured
> arguments to be given to the function.
>
> class reiterable():
>def __init__(self, itercall
Here is a class that creates a re-iterable from any callable, such as a
generator function, that returns an iterator when called, + captured
arguments to be given to the function.
class reiterable():
def __init__(self, itercall, *args, **kwds):
self.f = itercall # callable that returns a
On Fri, Oct 21, 2011 at 2:02 AM, Yingjie Lan wrote:
> Oops, my former reply has the code indentation messed up
> by the mail system. Here is a reformatted one:
>
>
> What if the generator involves a variable from another scope,
> and before re-generating, the variable changed its value.
> Also, th
On Thu, 20 Oct 2011 19:09:42 -0700, Yingjie Lan wrote:
>> Here's an example of an explicit request to revive the generator:
>
>
> g = (x*x for x in range(3))
> for x in g: print x
>> 0
>> 1
>> 4
> g = (x*x for x in range(3)) # revive the generator for x in g:
> print x #now t
On 10/20/2011 10:09 PM, Yingjie Lan wrote:
What if the generator is passed in as an argument
when you are writing a function? That is, the expression
is not available?
Secondly, it would be nice to automatically revive it.
For example, when another for-statement or other
equivalent is appli
- Original Message -
> From: Chris Angelico
> To: python-list@python.org
> Cc:
> Sent: Friday, October 21, 2011 4:27 PM
> Subject: Re: revive a generator
>
> On Fri, Oct 21, 2011 at 7:02 PM, Yingjie Lan wrote:
>> What if the generator involves a
- Original Message -
> From: Paul Rudin
>
> I'm not really sure whether you intend g to yield the original values
> after your "revive" or new values based on the new value of vo. But
> still you can make a class that supports the iterator protocol and does
> whatever you want (but you
On Fri, Oct 21, 2011 at 7:02 PM, Yingjie Lan wrote:
> What if the generator involves a variable from another scope,
> and before re-generating, the variable changed its value.
> Also, the generator could be passed in as an argument,
> so that we don't know its exact expression.
>
There's actually
Yingjie Lan writes:
>
>
> What if the generator involves a variable from another scope,
> and before re-generating, the variable changed its value.
> Also, the generator could be passed in as an argument,
> so that we don't know its exact expression.
>
vo = 34
g = (vo*x for x in range(3
- Original Message -
> From: Paul Rudin
> To: python-list@python.org
> Cc:
> Sent: Friday, October 21, 2011 3:27 PM
> Subject: Re: revive a generator
>
>
> The language has no explicit notion of a request to "revive" a
> generator. You could use th
- Original Message -
> From: Paul Rudin
> The language has no explicit notion of a request to "revive" a
> generator. You could use the same syntax to make a new generator that
> yeilds the same values as the one you started with if that's what you
>
sure why should we enforce that
> a generator can not be reused after an explicit
> request to revive it?
The language has no explicit notion of a request to "revive" a
generator. You could use the same syntax to make a new generator that
yeilds the same values as the one you started
> Here's an example of an explicit request to revive the generator:
>
g = (x*x for x in range(3))
for x in g: print x
> 0
> 1
> 4
g = (x*x for x in range(3)) # revive the generator
for x in g: print x #now this will work
> 0
> 1
> 4
>
> ChrisA
What if the generator is p
On Fri, Oct 21, 2011 at 12:46 PM, Yingjie Lan wrote:
>
> Thanks a lot to all who answered my question.
> I am still not sure why should we enforce that
> a generator can not be reused after an explicit
> request to revive it?
Here's an example of an explicit request to revive the generator:
>>>
- Original Message -
> From: Paul Rudin
> To: python-list@python.org
> Cc:
> Sent: Thursday, October 20, 2011 10:28 PM
> Subject: Re: revive a generator
>
> Yingjie Lan writes:
>
>> Hi,
>>
>> it seems a generator expression can be us
On 10/20/2011 9:23 AM, Yingjie Lan wrote:
it seems a generator expression can be used only once:
Generators are iterators. Once iterators raise StopIteration, they are
supposed to continue doing so.
A generator expression defines a temporary anonymous generator function
that is called once t
Yingjie Lan writes:
> Hi,
>
> it seems a generator expression can be used only once:
>
g = (x*x for x in range(3))
for x in g: print x
> 0
> 1
> 4
for x in g: print x #nothing printed
>
> Is there any way to revive g here?
>
Generators are like that - you consume them until t
On Fri, Oct 21, 2011 at 12:23 AM, Yingjie Lan wrote:
> Hi,
>
> it seems a generator expression can be used only once:
>
g = (x*x for x in range(3))
for x in g: print x
> 0
> 1
> 4
for x in g: print x #nothing printed
>
> Is there any way to revive g here?
If you're not generat
Hi,
it seems a generator expression can be used only once:
>>> g = (x*x for x in range(3))
>>> for x in g: print x
0
1
4
>>> for x in g: print x #nothing printed
>>>
Is there any way to revive g here?
Yingjie
--
http://mail.python.org/mailman/listinfo/python-list
22 matches
Mail list logo