Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #87972
| Path | csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <webmailgroups@gmail.com> |
| 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; 'skip:[ 20': 0.04; 'elif': 0.05; 'defaults': 0.07; 'wednesday,': 0.07; 'arguments': 0.09; 'exception,': 0.09; 'function:': 0.09; 'subject:Function': 0.09; 'try:': 0.09; 'valueerror:': 0.09; 'way:': 0.09; 'def': 0.12; 'jan': 0.12; '"current': 0.16; '(actually': 0.16; '......': 0.16; 'combinations': 0.16; "function's": 0.16; 'googled': 0.16; 'ivan': 0.16; 'reedy': 0.16; 'subject:avoiding': 0.16; 'subject:combinations': 0.16; 'wrote:': 0.18; 'message-----': 0.19; 'input': 0.22; 'error': 0.23; 'case.': 0.24; 'instance,': 0.24; 'question': 0.24; 'options': 0.25; 'header:In-Reply-To:1': 0.27; 'to:2**1': 0.27; 'function': 0.29; 'raise': 0.29; "i'm": 0.30; 'url:mailman': 0.30; 'code': 0.31; '25,': 0.31; '>>>>': 0.31; 'file:': 0.31; 'url:python': 0.33; 'implemented': 0.33; 'common': 0.35; 'except': 0.35; 'one,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'instances': 0.36; 'url:listinfo': 0.36; 'charset:us-ascii': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'should': 0.36; 'too': 0.37; 'email addr:python.org': 0.37; 'message-id:@gmail.com': 0.38; 'to:addr :python-list': 0.38; 'skip:- 10': 0.38; 'pm,': 0.38; 'little': 0.38; 'subject:': 0.39; 'skip:b 40': 0.39; 'to:addr:python.org': 0.39; 'url:mail': 0.40; 'how': 0.40; 'full': 0.61; 'march': 0.61; 're:': 0.63; 'such': 0.63; 'choose': 0.64; 'received:79': 0.64; 'email name:python-list': 0.65; 'here': 0.66; 'on...': 0.68; 'default': 0.69; '2015': 0.84; 'condition.': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:references:in-reply-to:subject:date:message-id:mime-version :content-type:content-transfer-encoding:thread-index :content-language; bh=zIQsfWh1BXZmnEh3L3uTfbxkvPMqpxqIgv6oiUL9esc=; b=kdeeX+Q/bYoaXyjY0WsnPdDmfDOF8OzI86wtI9zoMg8K95g4HQ9OTAoBrfXaWQ+LsC oR36PxZgosqoXcBqRy4mihbR6AaS2DuX1X6f3U+RD9iXFM7GH2EgmdjWD47EQomh9yOk gf5NMLSV42jYwjMWmkwRviM3wdN1bJH0oCcgUxXAfhLwZ1cZXSXDSPksZxyhb+3cDy7U MlHL0QtbSM1546oZ6JHgZ3hbGu3Pic1UEWc7zxVDGndnNn1uqWPqZG2o31OnO5UtdfFe yoiyIMOrtbkpy/dKek+fqAXxAsHzmDw+phbA4kBHgzI5Aae0F/80ST2jb22Spk/C4A4W DYWg== |
| X-Received | by 10.194.159.105 with SMTP id xb9mr21343026wjb.156.1427313044263; Wed, 25 Mar 2015 12:50:44 -0700 (PDT) |
| From | "Ivan Evstegneev" <webmailgroups@gmail.com> |
| To | "'Terry Reedy'" <tjreedy@udel.edu>, <python-list@python.org> |
| References | <009d01d06723$38860d50$a99227f0$@gmail.com> <meuvkb$e5t$1@ger.gmane.org> |
| In-Reply-To | <meuvkb$e5t$1@ger.gmane.org> |
| Subject | RE: Function Defaults - avoiding unneccerary combinations of arguments at input |
| Date | Wed, 25 Mar 2015 21:50:40 +0200 |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset="us-ascii" |
| Content-Transfer-Encoding | 7bit |
| X-Mailer | Microsoft Outlook 14.0 |
| Thread-Index | AQJmhzuVcfXrhgB79AcdClmCd0UxfgEFs1iim/ksjfA= |
| Content-Language | en-us |
| 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.158.1427313051.10327.python-list@python.org> (permalink) |
| Lines | 88 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1427313051 news.xs4all.nl 2970 [2001:888:2000:d::a6]:58356 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:87972 |
Show key headers only | View raw
Hello again ^_^,
Googled a bit, and found only one, a "ValueError" exception, but still don't
understand how it should be implemented in my case.
Should my code look like this one:
def my_fun(history=False, built=False, current=False, topo=None,
full=False, file=None):
try:
if currnet and full:
do something_1
elif current and file:
do something_2
elif history and full and file:
do something_3
except ValueError:
print("No valid input! Please try again ...")
...... some code here..............
Or I'm just too optimistic ^_^?
Thanks in advance,
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 — Next in thread | Find similar | Unroll thread
RE: Function Defaults - avoiding unneccerary combinations of arguments at input "Ivan Evstegneev" <webmailgroups@gmail.com> - 2015-03-25 21:50 +0200
Re: Function Defaults - avoiding unneccerary combinations of arguments at input Rob Gaddi <rgaddi@technologyhighland.invalid> - 2015-03-25 20:07 +0000
RE: Function Defaults - avoiding unneccerary combinations of arguments at input "Ivan Evstegneev" <webmailgroups@gmail.com> - 2015-03-25 22:43 +0200
csiph-web