__init__ keyword param for sub-class?
Bernhard Herzog
herzog at online.de
Thu Dec 23 15:35:32 EST 1999
"Fred L. Drake, Jr." <fdrake at acm.org> writes:
> I think it would be nice to have a way to specify that an argument
> *must* be given as a keyword parameter, and have it never be filled in
> from positional parameters. Perhaps something lispish:
>
> def __init__(self, *posArgs, **keyArgs, :myoption):
> self.__myoption = myoption
> return Pmw.ScrolledText.__init__(self, *posArgs, **keyArgs)
I agree that this would be a very useful feature, although I think
def __init__(self, *posArgs, myoption=, **keyArgs):
would be a more pythonic notation and the order of arguments makes more
sense to me. After all, the myoption argument is to be bound to the
local variable myoption and **keyArgs collects all remaining keyword
args.
In my example, myoption must be provided because it has no default value
and it must be a keyword argument. It should also be possible to assign
a default value with the obvious notation:
def __init__(self, *posArgs, myoption=1, **keyArgs):
In this case, myoption may be given as an argument or not, but if it's
given it must be a keyword arg.
Hmm, my post almost sounds like a proposal...
--
Bernhard Herzog | Sketch, a drawing program for Unix
herzog at online.de | http://sketch.sourceforge.net/
More information about the Python-list
mailing list