Last active
August 29, 2015 14:03
-
-
Save tenuki/f5eb5ea3274c58db3395 to your computer and use it in GitHub Desktop.
Name a lambda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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