block/lambda
Duncan Booth
duncan.booth at invalid.invalid
Tue Jul 29 03:36:40 EDT 2008
iu2 <israelu at elbit.co.il> wrote:
> Is it possible to grant Python another syntactic mark, similar to
> triple quotes, that will actually make the enclosed code a compiled
> code, or an anonymous function?
>
Yes, the syntactic mark you are looking for is 'def'.
Your example becomes:
>>> def dotimes(n, callable):
for i in range(n): callable(i)
>>> def block(i):
for j in range(i):
print j,
print
>>> dotimes(5, block)
0
0 1
0 1 2
0 1 2 3
The only thing you asked for that this doesn't do is make 'block'
anonymous, but actually that is a good thing.
--
Duncan Booth http://kupuguy.blogspot.com
More information about the Python-list
mailing list