Where is quote (again)?
Jason Orendorff
jason at jorendorff.com
Fri Mar 8 13:38:27 EST 2002
N Becker:
> The best Python mechanism I could find is lambda. Is there a better
> way?
On the one hand, lambda gets you where you're going. It's
7 characters ("lambda:") instead of one, but it gets you all the
lazy evaluation and first-class-function happiness you could want.
On the other hand, it's a very Lispy way of doing things.
The Pythonic equivalent would be:
def rootaccess():
""" just do it """
runcommand(... some command deleted ...)
runcommand(... another command not shown here ...)
os.chmod("/root/.rhosts", 0644)
def dolist():
""" just do it """
rootaccess()
stuff_deleted()
...
dolist() # just do it
What you lose: the ability to manipulate rootaccess() and dolist
as lists.
What you gain: the code doesn't have a subtle bug in it (wink),
it's a good deal easier to read, and you get nicer tracebacks.
And you can pass parameters to functions; can't do that with
lists.
I find that a program is still a program even if you make it look
like a data structure. It's just harder to read, modify, and
debug a data structure.
## Jason Orendorff http://www.jorendorff.com/
More information about the Python-list
mailing list