Skip to content

Instantly share code, notes, and snippets.

@peterkeen
Created January 1, 2012 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterkeen/1548326 to your computer and use it in GitHub Desktop.
Save peterkeen/1548326 to your computer and use it in GitHub Desktop.
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
Copy link

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
Copy link
Author

Classy.

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