Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
python "anonymous" functions
def some_anonymous_function(arg1, arg2):
print "%s %s" % (arg1, arg2)
def some_named_function(func, arg1, arg2):
func(arg1, arg2)
some_named_function(some_anonymous_function, arg1, arg2)
@jckarter

This comment has been minimized.

Copy link

@jckarter jckarter commented Jan 2, 2012

def fn(body):
    exec "def a_function" + body
    return a_function

fn("""(x):
    print x
    return x + 1""")(2)
@peterkeen

This comment has been minimized.

Copy link
Owner Author

@peterkeen peterkeen commented Jan 2, 2012

Classy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment