PEP 255: Simple Generators

Tim Peters tim.one at home.com
Fri Jun 22 18:42:20 EDT 2001


[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.





More information about the Python-list mailing list