Adding item in front of a list
Ben Hutchings
do-not-spam-ben.hutchings at businesswebsoftware.com
Mon Apr 14 06:53:03 EDT 2003
In article <b7deoe$devs8$1 at ID-169208.news.dfncis.de>,
Greg Ewing (using news.cis.dfn.de) wrote:
> Alex Martelli wrote:
>> I *hate* the few places in the Nutshell in which
>> I couldn't explain a function's behavior by means of Pythonic "optional
>> arguments", but rather had to resort to brackets meaning "optional"
>
> Maybe Python should in general allow optional arguments to
> be on the left instead of the right:
>
> def myrange(start = 0, stop):
> ...
>
> and then range() and insert() wouldn't be anomalous!
It could allow optional parameters to be defined anywhere in the list,
with the rules that:
1. Each keyword argument must correspond to a named parameter, unless
the function accepts arbitary keyword arguments. Keyword arguments
are assigned to parameters first.
2. There must be at least as many non-keyword arguments (m) as there are
unassigned required parameters (n). Unless the function accepts
arbitrary non-keyword arguments, there must be no more non-keyword
arguments than there are unassigned parameters.
3. The non-keyword arguments are assigned to the first (m - n) unmatched
optional parameters, and the n unassigned required parameters, in
order of parameter declaration.
Then range would be range(start=0, stop, step=1). But having existing
arguments match different parameters when you add arguments to the end
of the list could be confusing.
More information about the Python-list
mailing list