Scope question

Miki Tebeka miki.tebeka at zoran.com
Thu Mar 11 04:49:26 EST 2004


Hello Subhash,

> --- BEGIN ---
> counter = 0
> 
> def foo():
>   if counter < 10:
>     print "count = ", counter
>     counter += 1
> 
> foo()
> --- END ---
Today we have generators:
 >>> def foo():
	for count in range(10):
		print "count = ", count
		yield count
		count += 1
 >>> gen = foo()
 >>> gen.next()
count =  0
0
 >>> gen.next()
count =  1
1
 >>>

HTH.
Miki



More information about the Python-list mailing list