any trick to allow anonymous code blocks in python?
David Eppstein
eppstein at ics.uci.edu
Sat Jun 26 00:42:30 EDT 2004
In article <ROydndnd54-eYUHdRVn_iw at comcast.com>,
Doug Holton <insert at spam.here> wrote:
> > b.OnClick = (lambda : sys.stdout("You clicked me"))
>
> Yeah, I didn't mention the lambda option. I was thinking about
> designing a framework meant for beginners, and I'd rather stay away from
> lambdas. I'm surprised no one is even proposing support for anonymous
> code blocks in Python that support multiple lines, similar to what Ruby,
> Java, and other languages have.
Presumably the right (but non-Python) syntax for such a code block would
be:
def b.onClick():
print "You clicked me"
One reason for not adding this to Python would be the difficulty of
determining where the expression for the def'd object ends and where the
argument list for its definition begins. One could imagine working
backwards from the colon but I don't think Python's parser can do that,
and anyway if it's difficult for machines to parse it's also difficult
for humans to read.
--
David Eppstein http://www.ics.uci.edu/~eppstein/
Univ. of California, Irvine, School of Information & Computer Science
More information about the Python-list
mailing list