def get_num_args(f):
 if inspect.ismethod(f):
  return (f.__func__.__code__.co_argcount - 1)
 elif inspect.isfunction(f):
  return f.__code__.co_argcount
 else:
  raise TypeError(u'f should be a function or a method')

def get_num_args ( f ) : if inspect . ismethod ( f ) : return ( f . __func__ . __code__ . co_argcount - 1 ) elif inspect . isfunction ( f ) : return f . __code__ . co_argcount else : raise TypeError ( u'f should be a function or a method' )
find the number of arguments a function or method takes .