On 15/01/2015 06:39, Ian Kelly wrote:
On Wed, Jan 14, 2015 at 11:06 PM, Steven D'Aprano <st...@pearwood.info> wrote:
I have a function, which I put into an expression like this:

def func(a, b=None):
     global spam
     import math
     spam = [a, b]*3
     print spam
     del spam


value = [1, "hello", int, func]
del func

How would I use lambdak to write that as an expression

value = [1, "hello", int, ??????? ]

without the intermediate def?


# Untested, but seems like this should work.

value = [1, "hello", int, given_(lambda a, b=None:
     import_("math", lambda math:
     import_("operator", lambda operator:
     do_(lambda: operator.setitem(globals(), 'spam', [a, b]*3), lambda:
     print_(globals()['spam'], lambda:
     do_(lambda: operator.delitem(globals(), 'spam')))))))]


To the OP: I note that although import_ is used in the examples, it's
not found in the list of functions in the README.


Just what I've been looking for, highly readable, higly maintainable Python code. Please put this up as an Activestate recipe so it's preserved for prosperity, so that the entire world can see its asthetically pleasing properties.

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to