any trick to allow anonymous code blocks in python?
gabriele renzi
surrender_it at remove.yahoo.it
Sat Jun 26 05:27:54 EDT 2004
il Sat, 26 Jun 2004 00:58:49 -0500, Doug Holton <insert at spam.here> ha
scritto::
>Perhaps that should be a proposal for Python. It's like the decorators
>proposal (318). It just saves an extra step and is helpful for
>framework designers (people who use metaclasses, etc.). Instead of
>having to do this (or the other ways I mentioned):
>def onclick(..):
> ...code here
>b.onclick = onclick
>
>You can save a step and just do like you said:
>def b.onclick(...):
> ...code here
>
just my two cents: you can do this in ruby with nearly the same
syntax:
def b.onkclick()
..code here..
end
But even if that sounds like a great idea I have to admit it's not
widely used, probably because every framework with callbacks like
these already uses the common bind-a-function-to-this-event idiom,
instead of allowing method overriding.
Maybe this relates to the fact that GUI toolkits are mostly C/C++
based, and that years of limited languages have directed our mind
toward the 'you have to subclass' dictat. I wonder if SmallTalk GUIs
have something like this.
It would be nice to have singleton method definition with this syntax
in python, anyway.
More information about the Python-list
mailing list