Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #27716
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@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; 'exception': 0.03; 'arguments': 0.07; 'try:': 0.07; 'it;': 0.09; 'macros': 0.09; 'def': 0.10; 'aug': 0.13; 'language': 0.14; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'specified.': 0.16; 'subject:arithmetic': 0.16; 'wrote:': 0.17; 'thu,': 0.17; 'error.': 0.21; 'received:209.85.214.174': 0.21; 'this:': 0.23; 'header:In-Reply-To:1': 0.25; 'looks': 0.26; 'guess': 0.27; 'handling': 0.27; 'prevent': 0.27; 'message-id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'wrap': 0.29; 'call.': 0.30; 'evaluation': 0.30; 'function': 0.30; 'asking': 0.32; 'could': 0.32; 'print': 0.32; 'problem': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'exist': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'except': 0.36; 'possible': 0.37; 'ok,': 0.37; 'skip:z 10': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'mark': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'more': 0.63 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=R0dL2iTEte2GxxtUnjuTxgqiM77PvzBstT2s+OZxPaM=; b=upF7spuUDUVe0mm+DTiT7YqfO3D6xIWFmFM8k+4vI5U8ZYR3QmdInxOyLnYlUZHWDS uMLG1W1HL1hAdC0XijNzhGQ0wCTAOsfp+ISdG+lyzlxS3eEG9uiwjavQclgERa5k7t+7 DHwheU09/ANlcAoahJyyhjLJyOPUgYOlRtz9vIUKi5eJOJpoyhJaY48YDAxfO7KnhikE jzTYTwl1ENlbZDvfB/uL9+rMi6jW6Iw3aQFiEMVEPufY/GgTcjZDo5R+QzuPw7chBwiU MUSoKLb7ohRiwsR1s7PchGrqmbtL5f69nDbyhpDkql2w72VQKxT0+sLW1PYPvFoL/8pD J/Ag== |
| MIME-Version | 1.0 |
| In-Reply-To | <b1bd0444-e8ef-4f03-bd69-208e0c550147@googlegroups.com> |
| References | <8b9a5844-66b0-4940-946a-5e626462cdce@googlegroups.com> <mailman.3700.1345713371.4697.python-list@python.org> <b1bd0444-e8ef-4f03-bd69-208e0c550147@googlegroups.com> |
| Date | Thu, 23 Aug 2012 19:29:20 +1000 |
| Subject | Re: Guarding arithmetic |
| From | Chris Angelico <rosuav@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3704.1345714163.4697.python-list@python.org> (permalink) |
| Lines | 18 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1345714163 news.xs4all.nl 6972 [2001:888:2000:d::a6]:51927 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:27716 |
Show key headers only | View raw
On Thu, Aug 23, 2012 at 7:22 PM, Mark Carter <alt.mcarter@gmail.com> wrote:
> OK, so it looks like a solution doesn't exist to the problem as specified. I guess it's something that only a language with macros could accommodate.
You're asking for a function to prevent the evaluation of its
arguments from throwing an error. That's fundamentally not possible
with a function call. Exception handling is a much more normal way of
handling it; though if you prefer, you could wrap it up in a function
like this:
def safe_div(num,denom):
try:
return num/denom
except ZeroDivisionError:
return 42
print safe_div(1,0) # still a poor name though
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Guarding arithmetic Mark Carter <alt.mcarter@gmail.com> - 2012-08-23 02:05 -0700
Re: Guarding arithmetic Chris Angelico <rosuav@gmail.com> - 2012-08-23 19:16 +1000
Re: Guarding arithmetic Mark Carter <alt.mcarter@gmail.com> - 2012-08-23 02:22 -0700
Re: Guarding arithmetic Chris Angelico <rosuav@gmail.com> - 2012-08-23 19:29 +1000
Re: Guarding arithmetic Mark Carter <alt.mcarter@gmail.com> - 2012-08-23 02:22 -0700
Re: Guarding arithmetic Laszlo Nagy <gandalf@shopzeus.com> - 2012-08-23 11:23 +0200
Re: Guarding arithmetic Mark Carter <alt.mcarter@gmail.com> - 2012-08-23 02:47 -0700
Re: Guarding arithmetic Mark Carter <alt.mcarter@gmail.com> - 2012-08-23 02:47 -0700
Re: Guarding arithmetic Laszlo Nagy <gandalf@shopzeus.com> - 2012-08-23 11:28 +0200
Re: Guarding arithmetic Chris Angelico <rosuav@gmail.com> - 2012-08-23 19:30 +1000
Re: Guarding arithmetic Peter Otten <__peter__@web.de> - 2012-08-23 12:11 +0200
Re: Guarding arithmetic rusi <rustompmody@gmail.com> - 2012-08-23 10:15 -0700
Re: Guarding arithmetic Laszlo Nagy <gandalf@shopzeus.com> - 2012-08-23 13:01 +0200
Re: Guarding arithmetic MRAB <python@mrabarnett.plus.com> - 2012-08-23 12:21 +0100
Re: Guarding arithmetic Peter Otten <__peter__@web.de> - 2012-08-23 13:28 +0200
Re: Guarding arithmetic Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-08-23 15:11 +0100
Re: Guarding arithmetic Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-08-23 14:49 -0400
Re: Guarding arithmetic Chris Angelico <rosuav@gmail.com> - 2012-08-24 07:48 +1000
csiph-web