Last active
August 29, 2015 13:56
-
-
Save dheaney/9302997 to your computer and use it in GitHub Desktop.
Get the name of the first default argument from a python function
This file contains hidden or 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
| import inspect | |
| def first_default_arg(func): | |
| try: | |
| argspec = inspect.getargspec(func) | |
| return zip(argspec.args[-len(argspec.defaults):], argspec.defaults)[0][0] | |
| except: | |
| return None | |
| # def action(one, two, three=3): pass | |
| # first_default_arg(action) # => 'three' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment