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


Groups > comp.lang.python > #87962

Re: Function Defaults - avoiding unneccerary combinations of arguments at input

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'elif': 0.05; 'function:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:Function': 0.09; 'way:': 0.09; 'def': 0.12; 'jan': 0.12; '"current': 0.16; '(actually': 0.16; '......': 0.16; "function's": 0.16; 'ivan': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject: \n ': 0.16; 'subject:avoiding': 0.16; 'subject:combinations': 0.16; 'wrote:': 0.18; 'header:User-Agent:1': 0.23; 'error': 0.23; 'instance,': 0.24; 'question': 0.24; 'options': 0.25; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'raise': 0.29; 'code': 0.31; '>>>>': 0.31; 'file:': 0.31; 'common': 0.35; 'there': 0.35; 'instances': 0.36; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'little': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'full': 0.61; 'such': 0.63; 'choose': 0.64; 'here': 0.66; 'on...': 0.68; 'default': 0.69; 'condition.': 0.84; 'received:fios.verizon.net': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: Function Defaults - avoiding unneccerary combinations of arguments at input
Date Wed, 25 Mar 2015 14:43:06 -0400
References <009d01d06723$38860d50$a99227f0$@gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-98-114-97-173.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0
In-Reply-To <009d01d06723$38860d50$a99227f0$@gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.19
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.152.1427309020.10327.python-list@python.org> (permalink)
Lines 45
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1427309020 news.xs4all.nl 2842 [2001:888:2000:d::a6]:53890
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:87962

Show key headers only | View raw


On 3/25/2015 1:43 PM, Ivan Evstegneev wrote:
> Hello all ,
>
>
> Just a little question about function's default arguments.
>
> Let's say I have this function:
>
> def  my_fun(history=False, built=False, current=False, topo=None,
> full=False, file=None):
> 	if currnet and full:
> 		do something_1
> 	elif current and file:
> 		do something_2
> 	elif history and full and file:
> 		do something_3
> 	
>
> 	...... some code here..............
>
> and so on...
>
> I won't cover all the possibilities here (actually I don't use all of them
> ^_^).
>
> The question is about avoiding the response for unnecessary combinations?
>
> For instance, if user will call function this way:
>
>
>>>> my_fun(current=True, full=True, topo='some str', file="some_file")
>
> That will lead to function's misbehavior. As a particular case it will
> choose "current and full" condition.
>
>
> What is the common accepted way to deal with such unwanted situations?

Raise a value error for illegal combinations.  There are a few instances 
in the stdlib where 2 of several options are mutually incompatible.


-- 
Terry Jan Reedy

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


Thread

Re: Function Defaults - avoiding unneccerary combinations of arguments at input Terry Reedy <tjreedy@udel.edu> - 2015-03-25 14:43 -0400

csiph-web