Re: How to make an empty generator?

2010-02-24 Thread Aahz
In article , Michael Rudolf wrote: >Am 24.02.2010 23:58, schrieb Aahz: >> >> (abbreviated "gen iter" or "geniter"). > >lol I don't know why, but this sounds like a sex toy to me ;) And I thought only smutty Americans would have that twitch. -- Aahz (a...@pythoncraft.com) <*>

Re: How to make an empty generator?

2010-02-24 Thread Michael Rudolf
Am 24.02.2010 23:58, schrieb Aahz: (abbreviated "gen iter" or "geniter"). lol I don't know why, but this sounds like a sex toy to me ;) Regards, Michael -- http://mail.python.org/mailman/listinfo/python-list

Re: How to make an empty generator?

2010-02-24 Thread Aahz
In article , Terry Reedy wrote: > >Confusing generators and generator functions is, well, confusing. >For future reference, and clarity of communication in Pythonland, > >generator function: function that produces a generator when called; if >python coded, its body contains 'yield'. > >generator

Re: How to make an empty generator?

2010-02-24 Thread John Posner
generator An iterator produced by a generator function or a generator expression. -John +1. Can someone submit a documentation patch, please? Will do. -John [sorry if this is a dup] Done: #8012 "Revise generator-related Glossary entries" -John -- http://mail.python.org/mailman/listinfo/

Re: How to make an empty generator?

2010-02-24 Thread John Posner
On 2/24/2010 9:07 AM, Steve Holden wrote: John Posner wrote: Note that the Py2.6.4 documentation is inconsistent. AFAICT, it conforms to Terry's definitions above in most places. But the Glossary says: generator A function which returns an iterator.<... more ...> generator expressio

Re: How to make an empty generator?

2010-02-24 Thread Steve Holden
John Posner wrote: > On 2/19/2010 2:25 PM, Terry Reedy wrote: >> On 2/19/2010 12:44 PM, Stephen Hansen wrote: >> >>> Much to my embarrassment, sometime last night I realized I was being a >>> complete idiot, and the 'correct' way to handle this in my scenario is >>> really just: >>> >>> def initial

Re: How to make an empty generator?

2010-02-19 Thread John Posner
On 2/19/2010 2:25 PM, Terry Reedy wrote: On 2/19/2010 12:44 PM, Stephen Hansen wrote: Much to my embarrassment, sometime last night I realized I was being a complete idiot, and the 'correct' way to handle this in my scenario is really just: def initialize(): # do one time processing here retu

Re: How to make an empty generator?

2010-02-19 Thread Terry Reedy
On 2/19/2010 12:44 PM, Stephen Hansen wrote: Much to my embarrassment, sometime last night I realized I was being a complete idiot, and the 'correct' way to handle this in my scenario is really just: def initialize(): # do one time processing here return [] A generator is just a cal

Re: How to make an empty generator?

2010-02-19 Thread Stephen Hansen
On Fri, Feb 19, 2010 at 9:21 AM, Steven D'Aprano < st...@remove-this-cybersource.com.au> wrote: > On Fri, 19 Feb 2010 09:51:54 -0600, Robert Kern wrote: > >> But he doesn't say anything about side-effects. > > > > "I have some generators *that do stuff*, then start yielding results." > > [emphasis

Re: How to make an empty generator?

2010-02-19 Thread Steven D'Aprano
On Fri, 19 Feb 2010 09:51:54 -0600, Robert Kern wrote: > On 2010-02-19 00:21 AM, Steven D'Aprano wrote: >> On Fri, 19 Feb 2010 00:15:20 -0600, Robert Kern wrote: >> > What's the point of the wheel spinning? Did I miss something? I wonder whether it's for some kind of framework with a

Re: How to make an empty generator?

2010-02-19 Thread Robert Kern
On 2010-02-19 01:01 AM, Ben Finney wrote: Robert Kern writes: On 2010-02-18 18:33 PM, Ben Finney wrote: Robert Kern writes: He doesn't want *any* empty generator. He wants an iterator that executes some given side-effect-producing code then immediately raises the StopIteration. Ah, hm.

Re: How to make an empty generator?

2010-02-19 Thread Robert Kern
On 2010-02-19 00:21 AM, Steven D'Aprano wrote: On Fri, 19 Feb 2010 00:15:20 -0600, Robert Kern wrote: What's the point of the wheel spinning? Did I miss something? I wonder whether it's for some kind of framework with a main loop like for it in list_of_iterables: for x in it:

Re: How to make an empty generator?

2010-02-19 Thread Ben Finney
Arnaud Delobelle writes: > Ben Finney writes: > > Whether the OP needs to create a generator, or just any iterable > > type, isn't clear. > > If it walks and quacks like a duck... Anyway it's not just an iterable > object, it's an iterator. I can't really imagine that there would be > some code

Re: How to make an empty generator?

2010-02-19 Thread Arnaud Delobelle
Ben Finney writes: > Arnaud Delobelle writes: > >> What about >> foo = iter('') > > That doesn't return a generator. > > >>> foo = iter('') > >>> foo > > > Whether the OP needs to create a generator, or just any iterable type, > isn't clear. If it walks and quacks like a duck..

Re: How to make an empty generator?

2010-02-18 Thread Ben Finney
Robert Kern writes: > On 2010-02-18 18:33 PM, Ben Finney wrote: > > Robert Kern writes: > > > >> He doesn't want *any* empty generator. He wants an iterator that > >> executes some given side-effect-producing code then immediately > >> raises the StopIteration. > > > > Ah, hm. That's a rather pe

Re: How to make an empty generator?

2010-02-18 Thread Steven D'Aprano
On Fri, 19 Feb 2010 00:15:20 -0600, Robert Kern wrote: >>> What's the point of the wheel spinning? Did I miss something? >> >> I wonder whether it's for some kind of framework with a main loop like >> >> for it in list_of_iterables: >> for x in it: >> do_this_or_that (x) >> >> where,

Re: How to make an empty generator?

2010-02-18 Thread Robert Kern
On 2010-02-18 18:33 PM, Ben Finney wrote: Robert Kern writes: He doesn't want *any* empty generator. He wants an iterator that executes some given side-effect-producing code then immediately raises the StopIteration. Ah, hm. That's a rather perverse use case, but I'm sure the OP has their re

Re: How to make an empty generator?

2010-02-18 Thread Robert Kern
On 2010-02-18 19:28 PM, Mel wrote: Steven D'Aprano wrote: On Thu, 18 Feb 2010 17:30:54 -0600, Robert Kern wrote: > If all you want is a generator that doesn't yield anything, then > surely there isn't any one-time processing and you don't need the > comment? Sure there is. Python do

Re: How to make an empty generator?

2010-02-18 Thread Steve Holden
Stephen Hansen wrote: > On Thu, Feb 18, 2010 at 2:56 PM, Robert Kern > wrote: > > class once(object): >def __init__(self, func, *args, **kwds): >self.func = func >self.args = args >self.kwds = kwds > >def __ite

Re: How to make an empty generator?

2010-02-18 Thread Mel
Steven D'Aprano wrote: > On Thu, 18 Feb 2010 17:30:54 -0600, Robert Kern wrote: > >> > If all you want is a generator that doesn't yield anything, then >> > surely there isn't any one-time processing and you don't need the >> > comment? >> >> Sure there is. Python doesn't know that nothing ge

Re: How to make an empty generator?

2010-02-18 Thread Steven D'Aprano
On Thu, 18 Feb 2010 18:12:10 -0600, Robert Kern wrote: > He wants an iterator that executes some given side-effect-producing code > then immediately raises the StopIteration. Ah, that's the bit I missed! Yewww. Programming by side-effect... I hope the original poster has a good reason for such

Re: How to make an empty generator?

2010-02-18 Thread Ben Finney
Arnaud Delobelle writes: > What about > foo = iter('') That doesn't return a generator. >>> foo = iter('') >>> foo Whether the OP needs to create a generator, or just any iterable type, isn't clear. Robert Kern writes: > He doesn't want *any* empty generator. He wants an i

Re: How to make an empty generator?

2010-02-18 Thread Steven D'Aprano
On Thu, 18 Feb 2010 17:30:54 -0600, Robert Kern wrote: > > If all you want is a generator that doesn't yield anything, then > > surely there isn't any one-time processing and you don't need the > > comment? > > Sure there is. Python doesn't know that nothing gets yielded until it > hits the re

Re: How to make an empty generator?

2010-02-18 Thread Robert Kern
On 2010-02-18 17:36 PM, Stephen Hansen wrote: On Thu, Feb 18, 2010 at 2:56 PM, Robert Kern mailto:robert.k...@gmail.com>> wrote: class once(object): def __init__(self, func, *args, **kwds): self.func = func self.args = args self.kwds = kwds

Re: How to make an empty generator?

2010-02-18 Thread Robert Kern
On 2010-02-18 17:33 PM, Ben Finney wrote: Robert Kern writes: On 2010-02-18 16:25 PM, Stephen Hansen wrote: The only way I can figure out how to make an empty generator is: def gen(): # do my one-time processing here return yield Is there a better way

Re: How to make an empty generator?

2010-02-18 Thread Terry Reedy
a generator as part of a generalized system. The only way I can figure out how to make an empty generator is: def gen(): # do my one-time processing here return yield Is there a better way? The return/yield just makes me flinch slightly. I tried just raising Stop

Re: How to make an empty generator?

2010-02-18 Thread Arnaud Delobelle
On 18 Feb, 23:33, Ben Finney wrote: [...] > No need to define functions or classes; let a generator expression take > care of it for you:: > >     >>> foo = (x for x in list()) >     >>> foo.next() >     Traceback (most recent call last): >       File "", line 1, in >     StopIteration What abou

Re: How to make an empty generator?

2010-02-18 Thread Stephen Hansen
On Thu, Feb 18, 2010 at 3:36 PM, Stephen Hansen wrote: > My motivation is clarity, I can just see a colleague a year from now asking > me, "... what the hell is return / yield?" and although this is more > expensive, its less clear to me. > MORE clear to me. A class / decorator / whatever may be

Re: How to make an empty generator?

2010-02-18 Thread Stephen Hansen
On Thu, Feb 18, 2010 at 3:08 PM, Steven D'Aprano < st...@remove-this-cybersource.com.au> wrote: > On 2010-02-18 16:25 PM, Stephen Hansen wrote: > > The only way I can figure out how to make an empty generator is: > > > > def gen(): > >

Re: How to make an empty generator?

2010-02-18 Thread Stephen Hansen
On Thu, Feb 18, 2010 at 2:56 PM, Robert Kern wrote: > class once(object): >def __init__(self, func, *args, **kwds): >self.func = func >self.args = args >self.kwds = kwds > >def __iter__(self): >return self > >def next(self): >self.func(*self.arg

Re: How to make an empty generator?

2010-02-18 Thread Xavier Ho
re only > > > really "generators" because I want to call them /as/ a generator as > > > part of a generalized system. > > > > > The only way I can figure out how to make an empty generator is: > > > > > def gen(): > > > # do

Re: How to make an empty generator?

2010-02-18 Thread Ben Finney
Robert Kern writes: > On 2010-02-18 16:25 PM, Stephen Hansen wrote: > > The only way I can figure out how to make an empty generator is: > > > > def gen(): > > # do my one-time processing here > > > > return > > yi

Re: How to make an empty generator?

2010-02-18 Thread Robert Kern
ything ever-- they're only > > really "generators" because I want to call them /as/ a generator as > > part of a generalized system. > > > The only way I can figure out how to make an empty generator is: > > > def gen(): > > # do my on

Re: How to make an empty generator?

2010-02-18 Thread Steven D'Aprano
, I don't want them to yield anything ever-- they're only > really "generators" because I want to call them /as/ a generator as > part of a generalized system. > > The only way I can figure out how to make an empty generator is: > > def gen(): >

Re: How to make an empty generator?

2010-02-18 Thread Robert Kern
a generator as part of a generalized system. The only way I can figure out how to make an empty generator is: def gen(): # do my one-time processing here return yield Is there a better way? The return/yield just makes me flinch slightly. I tried just raising Stop

How to make an empty generator?

2010-02-18 Thread Stephen Hansen
The only way I can figure out how to make an empty generator is: def gen(): # do my one-time processing here return yield Is there a better way? The return/yield just makes me flinch slightly. I tried just raising StopIteration at the end, but of course that didn't