nntp2http.com
Posting
Suche
Optionen
Hilfe & Kontakt

rekursiver Generator

Von: Thomas Orgelmacher (trash@odbs.org) [Profil]
Datum: 10.10.2009 12:34
Message-ID: <hapnvt$cnu$00$1@news.t-online.com>
Newsgroup: de.comp.lang.python
Hallo zusammen!

Ich hoffe 'mal, das ist jetzt keine FAQ. Aber als Python-Neuling
komme ich hier absolut nicht weiter:

def t(n):
yield n
if(n < 10):
t(n + 1)

for i in t(0):
print(i)

Warum tut das so nicht? Wenn ich das richtig verstanden habe,
wird der komplette Zustand einer Funktion bei einem yield gesichert
und beim nächsten "Aufruf" wird nach dem yield weitergemancht.
Das funktioniert auch soweit (ich habe testhalber 'mal nach jeder
Zeile ein print eingefügt), aber die Rekursion funktioniert nicht.


Gruß,

Orgel

--
I have seen things you lusers would not believe.  I've seen Sun
monitors on fire off the side of the multimedia lab. I've seen
NTU lights glitter in the dark near the Mail Gate. All these
things will be lost in time, like the root partition last week.

[ Auf dieses Posting antworten ]

Antworten