Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #35652

Re: Function Parameters

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'argument': 0.04; '*args,': 0.07; 'arguments': 0.07; 'caller': 0.07; 'suppose': 0.07; 'python': 0.09; 'arg': 0.09; 'argument:': 0.09; 'arguments,': 0.09; 'kwargs': 0.09; 'positional': 0.09; 'similar,': 0.09; 'spec': 0.09; 'subject:Function': 0.09; 'def': 0.10; 'dec': 0.15; 'argument.': 0.16; 'defaults.': 0.16; 'inputs': 0.16; 'keyword.': 0.16; 'received:209.85.160.42': 0.16; 'wrote:': 0.17; 'thu,': 0.17; 'assignment': 0.22; 'dependent': 0.23; 'pass': 0.25; 'header :In-Reply-To:1': 0.25; '(which': 0.26; 'used,': 0.27; 'message- id:@mail.gmail.com': 0.27; 'arguments.': 0.29; 'optional': 0.29; 'this.': 0.29; 'knows': 0.30; 'keyword': 0.30; 'function': 0.30; 'sense': 0.31; 'could': 0.32; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'possible': 0.37; 'two': 0.37; 'ones': 0.37; 'passed': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'takes': 0.39; 'called': 0.39; 'header:Received:5': 0.40; 'first': 0.61; 'more': 0.63; 'here': 0.65; 'presumably': 0.84; 'to:name:python': 0.84; 'vain': 0.84; 'valid)': 0.84; '1:47': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=cCJAe0SDnflLT4cZfFh/hxAClsGm6mjWV9hkW+f90Z8=; b=fl3/dYuHrGtUXs5XS6tQA1t/CgfA2QRAM/4EMOrslCsnX+Z0xZviwIuRfyI2+HPALo eKJTvuzbm0n17wVrUq/t82GUguRYb8vtDa3/DP2TuWwi/qBxj3X+4h+E48Sr9AAEDFwu 5thPqoh9fEDBlgPzqlOjD6srh5Z/VIJGJTI7d9CB0QY05obvYlbcWqCNWjatpi0TAppH asNIQVTAgt4TEpdlp6KjEhNX+y0kgop4/ubI6ZMr4nxvqdd0P6j5swPBxnXTPu42fk9q TUIIjUtv6h6TwUpom4c+hetO77afHvacPsPJAbYY3ih2rgNwdedECEeyFP52uJ1gN4ax EC2A==
MIME-Version 1.0
In-Reply-To <assp.07088be20f.92097A6A775D5147B1078E3F15430B9234A0F2BA@prato.activenetwerx.local>
References <92097A6A775D5147B1078E3F15430B9234A0F238@prato.activenetwerx.local> <CALwzidmKXuHmGWMAoJbeiCxmPpmqd1tvAVxDuZZTAzL0TbgC_A@mail.gmail.com> <assp.07088be20f.92097A6A775D5147B1078E3F15430B9234A0F2BA@prato.activenetwerx.local>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Thu, 27 Dec 2012 14:01:19 -0700
Subject Re: Function Parameters
To Python <python-list@python.org>
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1368.1356642118.29569.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1356642118 news.xs4all.nl 6958 [2001:888:2000:d::a6]:52170
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:35652

Show key headers only | View raw


On Thu, Dec 27, 2012 at 1:47 PM, Joseph L. Casale
<jcasale@activenetwerx.com> 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.

But the caller knows the order of the arguments, so if they just pass
two arguments positionally, then presumably those first two arguments
are the ones that they intend.

> 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 designate arguments as keyword-only by placing
them after the * argument:

def example(self, *args, keyword1, keyword2=None):
    # Takes one or more positional arguments.
    # Required argument keyword1 and optional argument keyword2
    # can only be passed by keyword.
    pass

def example2(self, *, keyword='foo'):
    # Takes exactly one positional argument.
    # Optional argument keyword can only be passed by keyword.
    pass

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Function Parameters Ian Kelly <ian.g.kelly@gmail.com> - 2012-12-27 14:01 -0700

csiph-web