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


Groups > comp.lang.python > #87968

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

From "Ivan Evstegneev" <webmailgroups@gmail.com>
References <009d01d06723$38860d50$a99227f0$@gmail.com> <meuvkb$e5t$1@ger.gmane.org>
Subject RE: Function Defaults - avoiding unneccerary combinations of arguments at input
Date 2015-03-25 21:22 +0200
Newsgroups comp.lang.python
Message-ID <mailman.157.1427311384.10327.python-list@python.org> (permalink)

Show all headers | View raw


Hi Terry, 

Thanks for answer, I'll google these stdlib instances.


Sincerely,

Ivan.

> -----Original Message-----
> From: Python-list [mailto:python-list-
> bounces+webmailgroups=gmail.com@python.org] On Behalf Of Terry Reedy
> Sent: Wednesday, March 25, 2015 20:43
> To: python-list@python.org
> Subject: Re: Function Defaults - avoiding unneccerary combinations of
> arguments at input
> 
> 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
> 
> --
> https://mail.python.org/mailman/listinfo/python-list

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


Thread

RE: Function Defaults - avoiding unneccerary combinations of arguments at input "Ivan Evstegneev" <webmailgroups@gmail.com> - 2015-03-25 21:22 +0200

csiph-web