def func(msg, a=None, b=False, c='', d=0):
    print(msg)
for arg, val in sorted(func.actual_kwargs.items()):
    print('  %s: %s' % (arg, val))
func("I'm only passing a", a='a')
func("Here's b and c", b=True, c='c')
func('All defaults', a=None, b=False, c='', d=0)
func("Nothin'")
try:
    func('Invalid kwarg', e='bogon')
except TypeError as err:
    print('Invalid kwarg\n  %s' % err)
Getting the the keyword arguments actually passed to a Python method