block/lambda

jiri.zahradil at gmail.com jiri.zahradil at gmail.com
Tue Jul 29 16:26:38 CEST 2008


> 2. Will it be possible in Python 3.0 to do the following:
>
> >>> def dotimes(n, callable):
>
>         for i in range(n): callable()
>
> >>> def block():
>
>         nonlocal i
>         for j in range(i):
>                 print j,
>         print

dotimes seems ok and what is wrong with that function "block"? You do
not need to specify that i is "nonlocal", global i will be used.

>>> i=10
>>> def block():
        for j in range(i):
            print j,
        print
>>> block()
0 1 2 3 4 5 6 7 8 9

Jiri



More information about the Python-list mailing list