> -----Original Message----- > From: Python-list [mailto:python-list- > bounces+webmailgroups=gmail....@python.org] On Behalf Of Rob Gaddi > Sent: Wednesday, March 25, 2015 22:07 > To: python-list@python.org > Subject: Re: Function Defaults - avoiding unneccerary combinations of > arguments at input > > On Wed, 25 Mar 2015 21:50:40 +0200, Ivan Evstegneev wrote: > > > 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. > > > > A) Please don't top-post. Put your new stuff below previous context, so it > flows in readable order. > > B) You've got the concept backwards. You're not trying to catch a ValueError > because one came up below your function. Your function was called > incorrectly, and you're kicking the responsibility for dealing with it back to the > guy who got it wrong. > > def my_fun(....): > if invalid_argument_combination: > raise ValueError('Hey jerk, read the documentation.') > > # otherwise you do your thing in here. > > > -- > Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email > address domain is currently out of order. See above to fix. > -- > https://mail.python.org/mailman/listinfo/python-list
Ok thanks fo the answer. Got it. About top-posting... will need to tweak Outlook settings. -- https://mail.python.org/mailman/listinfo/python-list