Created
September 9, 2009 00:56
-
-
Save anfedorov/183375 to your computer and use it in GitHub Desktop.
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
from inspect import getargspec | |
def filter_dict(d, fltr): | |
return dict( (x, d[x]) for x in fltr if x in d ) | |
def apply_some(f, *args, **kwargs): | |
fspec = getargspec(f) | |
return f(*args, **kwargs) if fspec.keywords else f( *args, **filter_dict(kwargs, fspec.args) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment