any trick to allow anonymous code blocks in python?
Doug Holton
insert at spam.here
Fri Jun 25 18:51:58 EDT 2004
Is there any metaclass trick or something similar to allow anonymous
code blocks?
I'd like to be able to let users do something like this fictitious example:
b = Button()
b.OnClick =:
print "you clicked me"
But that would require adding a special "=:" operator to bind a code
block to a function.
Is there any PEP for something like that? I see 310 might allow:
b=Button()
with b.OnClick:
print "you clicked me"
I know I can already do it like these examples:
def OnClick(self,event):
print "you clicked me"
b.OnClick = OnClick
or
b = Button(OnClick=OnClick)
or subclassing Button.
More information about the Python-list
mailing list