PEP 255: Simple Generators

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Sat Jun 23 02:59:47 EDT 2001


Sat, 23 Jun 2001 00:03:33 +0200 (CEST), Carsten Geckeler <uioziaremwpl at spammotel.com> pisze:

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

Actually it's the opposite side with generators:

class: the body is executed immediately
def: the body is executed when called
generator: the body is executed when called twice (g().next())

-- 
 __("<  Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK



More information about the Python-list mailing list