Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsreader4.netcologne.de!news.netcologne.de!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.019 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'suppose': 0.05; 'received:209.85.214.174': 0.13; 'received:mail- iw0-f174.google.com': 0.13; 'wrote:': 0.15; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'lambda': 0.16; 'operators,': 0.16; '16,': 0.16; 'pm,': 0.16; 'math': 0.21; 'header:In-Reply-To:1': 0.22; 'missed': 0.24; 'received:209.85.214': 0.28; 'sat,': 0.28; 'message- id:@mail.gmail.com': 0.28; 'import': 0.29; 'object': 0.30; 'version': 0.30; 'subject:?': 0.31; 'usual': 0.32; 'to:addr :python-list': 0.34; 'there': 0.34; 'addition,': 0.36; 'but': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.38; 'steven': 0.38; 'think': 0.38; 'else': 0.38; "there's": 0.39; 'to:addr:python.org': 0.39; 'received:209': 0.40; 'something.': 0.91; 'subject:there': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=ie0Sq9JKoqHGw7w/W2tjwEE2p7b9z9+G+JOVbnVMsdo=; b=QEge0dpqrsXpXyBA52ntMcMjh2h00PUmh4cZgYuFKmGQOzVOEJG0PugORc9KINtNMb UZxhlDfho5658UJq4QXgBDvhYq+VrAl4mOC/LxxFaMk6KYCSMGDfHRFMSnxLZ8rqNCzs 2pYg1I/mVQAcyUMToqSzHOm6+zRQ1f9cgb0U0= MIME-Version: 1.0 In-Reply-To: <4e214d5a$0$29975$c3e8da3$5496439d@news.astraweb.com> References: <4e214d5a$0$29975$c3e8da3$5496439d@news.astraweb.com> Date: Sat, 16 Jul 2011 19:14:47 +1000 Subject: Re: Is there a way to customise math.sqrt(x) for some x? From: Chris Angelico 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 16 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1310807690 news.xs4all.nl 23918 [2001:888:2000:d::a6]:59773 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:9613 On Sat, Jul 16, 2011 at 6:35 PM, Steven D'Aprano wrote: > I have a custom object that customises the usual maths functions and > operators, such as addition, multiplication, math.ceil etc. > > Is there a way to also customise math.sqrt? I don't think there is, but I > may have missed something. Only thing I can think of is: import math math.sqrt=lambda(x) x.__sqrt__(x) if x.whatever else math.sqrt(x) I don't suppose there's a lambda version of try/catch? ChrisA