I have a function which has a large number of arguments.

I want to have the names of the arguments available in the help() function, but I want the results as a dict.

At the moment, I have the following:

def myfunc(thisparameter,thatparameter,hostname,password,port,service,url,someotherparameter, etc, andsoforth):
   return some_function(dict(thisparameter=thisparameter,thatparameter=thatparameter,hostname=hostname,port=port,service=service,url=url,someotherparameter=someotherparameter, etc=etc, andsoforth=andsoforth))

I can't just use kwargs, since that means the help() function won't show the parameters. I have a lot of these. I understand that I can use __doc__, but that still shows the parameters as **kwargs.

closed as unclear what you're asking by Scant Roger, Ixrec, user40980 Nov 27 '15 at 20:58

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Maybe I'm missing something, but why not document the actual parameters? The function doesn't appear to be using kwargs at all, so why would you want to document kwargs? – Ixrec Nov 27 '15 at 20:32
  • For clarification, I was asking exactly what @Tibo answered. I wanted it to be documented as if there was no kwargs, but to get the parameters in a dict. locals() is the (a?) correct method to do this. – AMADANON Inc. Nov 29 '15 at 20:18

You could use the locals() hack proposed in this SO question, like so:

def myfunc(thisparameter,thatparameter):
  return some_function(**locals())

This allows you to explicit arguments to myfunc and call your implementation without the need to repeat all the arguments.

It is not bulletproof. For a more "secure" version you might want to use inspect.

(As a side note, I'm flagging this question for migration to SO. I'm however not so sure if this is a duplicate as you have the help twist that is not mentioned in the SO question)

  • This is almost exactly the answer I was looking for - minus the **, so some_function gets a dict. – AMADANON Inc. Nov 29 '15 at 20:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.