Re: Function Parameters

Discussion in 'Python' started by Oscar Benjamin, Dec 27, 2012.

  1. On 27 December 2012 20:47, Joseph L. Casale <> wrote:
    >> Don't use kwargs for this. List out the arguments in the function
    >> spec and give the optional ones reasonable defaults.

    >
    >> I only use kwargs myself when the set of possible arguments is dynamic
    >> or unknown.

    >
    > Gotch ya, but when the inputs to some keywords are similar, if the function is called
    > with two of three (which is valid) and the arg name isn't used, the assignment is order
    > dependent and arbitrary in a sense and I can not distinguish.
    >
    > It would be nice if you could force the keyword to be mandatory to forgo the assumption
    > in assignment like kwargs provides with gets. I suppose all the time wasted here is in vain
    > as the caller could blunder elsewhere...


    In Python 3 you can do this using keyword-only arguments like so (note
    the asterisk that separates keyword arguments from positional
    arguments):

    def my_func(self, *, some_key=MISSING, another_key=MISSING):


    Oscar
    Oscar Benjamin, Dec 27, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jonck van der Kogel
    Replies:
    2
    Views:
    976
    Jonck van der Kogel
    May 27, 2004
  2. Boris Sargos
    Replies:
    3
    Views:
    414
    Boris Sargos
    Apr 23, 2004
  3. Jason
    Replies:
    2
    Views:
    506
    Jonathan Mcdougall
    May 13, 2006
  4. kito
    Replies:
    2
    Views:
    413
  5. Florian Loitsch
    Replies:
    11
    Views:
    245
    Michael Winter
    Mar 15, 2005
Loading...

Share This Page