PEP 255: Simple Generators
Carsten Geckeler
uioziaremwpl at spammotel.com
Sat Jun 23 03:21:56 EDT 2001
On Fri, 22 Jun 2001, Tim Peters wrote:
> [Carsten Geckeler]
> > ...
> > I just wanted to point out that "calling a class" (i.e. creating an
> > instance by calling class(args)) also returns an object, but that this
> > is of course not a reason to define it with "def", because the way the
> > definition is evaluated and what is returned is completly different as
> > how a function definition is evaluated (as you pointed out). And the
> > same with generators.
>
> If you're only interested in the first 100 nanoseconds of a generator's
> life, that's true <wink>. But when you write a generator, or analyze a
> generator, or think about a generator, or step thru a generator in a
> debugger (etc), they're just resumable functions; much like class methods
> are just functions with a magical first argument. We spell class methods
> with "def" to emphasize the similarities; ditto for generators. That
> doesn't mean differences don't exist, but that the similarities are so deep
> that harping on the differences is more distracting than helpful.
I think we came to the core point. It seems that some people have exactly
the other oppinion, i.e. that the differences how a generator is evaluated
and used is so different that a different "def" line would be helpful for
many people. Could you tell me, how e.g. a "generator" statement would
be distracting? I can't see how a more clearifying statement could
possibly distract people.
The changed use of "def" in class definitions is clear for me, because all
the method "def"s are inside of a `class definition scope'. I've problems
that the generator "def" changes behaviour (and that quite heavily in my
oppinion, because they don't return what they `should', i.e. what is
written in the "return" statements) in `normal scope' just by any
occurence of a "yield" statement, even if it's buried somewhere in the
suite.
Cheers, Carsten
--
Carsten Geckeler
More information about the Python-list
mailing list