Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'argument': 0.04; 'explicitly': 0.04; 'suppose': 0.07; 'defined.': 0.09; 'here?': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.10; 'possible?': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:arithmetic': 0.16; 'wrote:': 0.17; 'define': 0.20; 'trying': 0.21; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; '(most': 0.27; 'header:X -Complaints-To:1': 0.28; 'prints': 0.29; "i'm": 0.29; 'function': 0.30; 'problem.': 0.32; 'from:addr:yahoo.co.uk': 0.32; 'could': 0.32; 'print': 0.32; 'certain': 0.33; 'like:': 0.33; 'to:addr :python-list': 0.33; 'requirements': 0.33; 'something': 0.35; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'passed': 0.37; 'subject:: ': 0.38; 'mark': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'valuable': 0.60; "you've": 0.61; 'here': 0.65; 'charset:windows-1252': 0.65; '666': 0.84; 'numerous': 0.91; 'received:2': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: Guarding arithmetic Date: Thu, 23 Aug 2012 15:11:43 +0100 References: <8b9a5844-66b0-4940-946a-5e626462cdce@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: host-2-98-202-33.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:14.0) Gecko/20120713 Thunderbird/14.0 In-Reply-To: <8b9a5844-66b0-4940-946a-5e626462cdce@googlegroups.com> X-Antivirus: avast! (VPS 120823-0, 23/08/2012), Outbound message X-Antivirus-Status: Clean X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1345730984 news.xs4all.nl 6969 [2001:888:2000:d::a6]:36551 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:27734 On 23/08/2012 10:05, Mark Carter wrote: > Suppose I want to define a function "safe", which returns the argument passed if there is no error, and 42 if there is one. So the setup is something like: > > def safe(x): > # WHAT WOULD DEFINE HERE? > > print safe(666) # prints 666 > print safe(1/0) # prints 42 > > I don't see how such a function could be defined. Is it possible? > Well you've already got lots of answers but I'm not certain about what you're trying to achieve. If you could explicitly state your requirements I'm sure that the numerous MVPs (Most Valuable Pythonistas) here would come up with The Best Solution ™ to your problem. -- Cheers. Mark Lawrence.