Skip to content

Instantly share code, notes, and snippets.

@dheaney
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save dheaney/9302997 to your computer and use it in GitHub Desktop.

Select an option

Save dheaney/9302997 to your computer and use it in GitHub Desktop.
Get the name of the first default argument from a python function
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