Skip to content

Instantly share code, notes, and snippets.

@tenuki
Last active August 29, 2015 14:03
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 tenuki/f5eb5ea3274c58db3395 to your computer and use it in GitHub Desktop.
Save tenuki/f5eb5ea3274c58db3395 to your computer and use it in GitHub Desktop.
Name a lambda
# A very simple recipe to allow you easily name lambda-objects
#(or other kind of objects, callable, for example, partial
#objects) you create, with little overhead and friendly syntax.
def Name(**kw):
assert len(kw)==1
name, obj = kw.items()[0]
obj.func_name = name
return obj
def main():
f = Name(CheckExists=lambda:os.path.exists(some_filename))
print f
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment